我有一个具有自定义数据类型的数据库FollowEntityType
作为一个列。
@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 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()
该错误是针对实体类型列表字段,根据错误,该类型应该是数据库中的列之一。我已经有了关注实体类型作为列类型之一。我不明白为什么它会失败。请帮助我,因为我找不到任何解决方案来解决这个问题。