Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type

I have a DB which has a custom data type FollowEntityType as a column.

@Entity(primaryKeys = arrayOf("id", "type"), tableName = "follow_info")
data class FollowInfoEntity(
        @ColumnInfo(name = "id") var id: String,
        @ColumnInfo(name = "type") var type: FollowEntityType,
)

Since it is a custom data type, I have defined a type converter.

class FollowDatabaseTypeConverter {

    @TypeConverter
    fun toFollowEntity(entityType: String?): FollowEntityType? {
        return FollowEntityType.from(entityType ?: Constants.EMPTY_STRING)
    }

    @TypeConverter
    fun toString(entityType: FollowEntityType?): String? {
        return entityType?.name
    }
}

This works fine and I am able to store/retrieve values in the DB. However, in one of the queries, the build fails.

This is the query.

@Query("select * from follow_info where type in (:entityTypeList)")
fun getFollowedEntitiesByType(entityTypeList: List<FollowEntityType>) : List<FollowInfoEntity>

The build fails with the following error.

Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
    java.util.List<? extends FollowEntityType> entityTypeList, @org.jetbrains.annotations.NotNull()

The error is for entityTypeList field, and according to the error, this type should be one of the columns in the DB. I already have FollowEntityType as one of the column types. I don't understand why it is failing. Please help me out as I am not finding any solution to solve this problem.

like image 958
thedarkpassenger Avatar asked Nov 29 '22 05:11

thedarkpassenger


1 Answers

This error occurred for me when I updated the kotlin library version without updating the room database version.

I was using Kotlin 1.5.10 and Room version 2.2.5 that caused the problem. Changing Room to 2.3.0 fixed the error.

like image 135
Vasudev Avatar answered Dec 04 '22 00:12

Vasudev