【原創】升級kotlin 1.6.x後採坑
阿新 • • 發佈:2021-12-17
- 我資料庫使用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就好了,沒深入研究,我是能用就好,哈哈
- Room查詢資料,如果返回的是@Entity標識的物件,那必須全部欄位返回,@Query中SQL不能查詢單個欄位否則報錯
···
@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 或者 自定義一個類僅包含查詢的欄位但是不要使用@Entity標識就可以了