Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type(查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组)
本文介绍了查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据库,其自定义数据类型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()
错误针对entityTypeList字段,根据错误,此类型应该是数据库中的列之一。我已经将FollowEntityType作为列类型之一。我不明白为什么它会失败。请帮帮我,因为我找不到任何解决方案来解决此问题。
推荐答案
当我更新kotlin库版本而没有更新聊天室数据库版本时,发生此错误。
我使用的是导致问题的Kotlin 1.5.10和Room版本2.2.5。将房间更改为2.3.0已修复此错误。
这篇关于查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:查询方法参数应该是可以转换为数据库列的类型,或者是包含此类类型的列表/数组


猜你喜欢
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01