Room: Receiving error when using @Transaction

前端 未结 1 936
猫巷女王i
猫巷女王i 2021-02-18 23:42

I\'m have a method annotated with @Transaction in my DAO class, which is causing the following error:

A DAO method can be annotated with only one of the f

相关标签:
1条回答
  • 2021-02-19 00:11

    According to the transaction documentation

    Marks a method in an abstract Dao class as a transaction method.

    Change your class to:

    @Dao abstract class Dao {
    
        @Insert(onConflict = REPLACE) abstract fun insertList(chacaras: List<String>)
    
        @Query("SELECT * FROM chacara WHERE cityId = :cityId")
        abstract fun getListOfCity(cityId: String): LiveData<List<String>>
    
        @Delete abstract fun deleteList(chacaraList: List<String>)
    
        @Transaction
        open fun updateList(list: List<String>){
            deleteList(list)
            insertList(list)
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题