Issue in query parameters:An Annotation argument must be a compile time constant

I am trying to set room query parameters by Enum:

enum class Status(val status:Int){

the query:

@Query("SELECT * FROM questions where status=${Status.NOTANSWERED.status}")
    suspend fun getNotAnsweredQuestions()

IDE get error:

An Annotation argument must be a compile time constant

I have also read this topic but not solved my issue


Look at this recent issuetracker discussion; like the IDE error says, your value is not a compile time constant; using an enum value or an enum value property directly in a query annotation is not possible:

The final comment #5 ( suggests a fairly straightforward workaround: create another function that passes the value:

@Query("SELECT * FROM questions where status=:status")
protected suspend fun getQuestions(status: Int)

suspend fun getNotAnsweredQuestions() = getQuestions(Status.NOTANSWERED.status)

In addition I recommend using a @TypeConverter, so that you can pass your enum values directly (Status.NOTANSWERED) instead of their properties (Status.NOTANSWERED.status).