Android 查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组

Android 查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组,android,sqlite,kotlin,android-room,Android,Sqlite,Kotlin,Android Room,我有一个数据库,它有一个自定义数据类型followerEntityType作为列 @Entity(primaryKeys = arrayOf("id", "type"), tableName = "follow_info") data class FollowInfoEntity( @ColumnInfo(name = "id") var id: String, @ColumnInfo

我有一个数据库,它有一个自定义数据类型
followerEntityType
作为列

@Entity(primaryKeys = arrayOf("id", "type"), tableName = "follow_info")
data class FollowInfoEntity(
        @ColumnInfo(name = "id") var id: String,
        @ColumnInfo(name = "type") var type: FollowEntityType,
)
因为它是一种自定义数据类型,所以我定义了一个类型转换器

class FollowDatabaseTypeConverter {

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

    @TypeConverter
    fun toString(entityType: FollowEntityType?): String? {
        return entityType?.name
    }
}
这很好,我能够在数据库中存储/检索值。但是,在其中一个查询中,构建失败

这就是问题所在

@Query("select * from follow_info where type in (:entityTypeList)")
fun getFollowedEntitiesByType(entityTypeList: List<FollowEntityType>) : List<FollowInfoEntity>
@Query(“从follow\u info中选择*,其中键入(:entityTypeList)”)
fun GetFollowDentitiesByType(entityTypeList:List):列表
生成失败,出现以下错误

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()
查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组。可以考虑为此添加一个类型适配器。

java.util.List我也遇到了同样的问题,并报告了一个bug

当我更新kotlin库版本而不更新room数据库版本时,发生了这个错误


我使用的是Kotlin 1.5.10和Room版本2.2.5,这导致了问题。将房间更改为2.3.0修复了错误。

您在哪里将以下DatabaseTypeConverter添加为
TypeConverters
?在
@实体
@数据库
之上。如果它在@Entity上,那么它对您的
@Dao
查询没有影响。请阅读@musooff中有关
@TypeConverters
的更多信息:我将它包括在数据库顶部。那么,可能是因为它是
列表
。尝试将
列表
的类型转换器添加到
列表
。如果是这样,那么它一定是一个bug,您可以报告它。