【原创】升级kotlin 1.6.x后采坑

  1. 我数据库使用Room, Dao层查询方法使用了suspend
    @Update(onConflict = OnConflictStrategy.IGNORE)
   suspend fun update(listMenu: List<TbMenu>)

然后就会报错,
error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

直接去掉suspend就好了,没深入研究,我是能用就好,哈哈

  1. Room查询数据,如果你对象是data 修饰的,那必须全部字段返回构造中的字段否则报错

···
@Query("SELECT ID,NAME,SUBJECTID,PICTURENAME FROM abcdefg")
fun getPayWay2(): Flow<List>
···

: The columns returned by the query does not have the fields [code,useState,posIseMark,serialNum] in com.baiyuas.TbPayWay even though they are annotated as non-null or primitive. Columns returned by the query: [id,name,subjectid,picturename]
    public abstract kotlinx.coroutines.flow.Flow<java.util.List<com.baiyuas.TbPayWay>> getPayWay2();
                                                           

所以这里必须是SELECT * FROM abcdefg 或者 自定义一个类仅包含查询的字段

另外我发现这个好像也区分大小写,如果你实体类中字段是大写,一般也会报错,框架编译返回的是小写的

posted @ 2021-12-17 10:13  拜雨  阅读(633)  评论(0编辑  收藏  举报