Room: Receiving error when using @Transaction

前端 未结 1 928
猫巷女王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)
    
        @Query("SELECT * FROM chacara WHERE cityId = :cityId")
        abstract fun getListOfCity(cityId: String): LiveData>
    
        @Delete abstract fun deleteList(chacaraList: List)
    
        @Transaction
        open fun updateList(list: List){
            deleteList(list)
            insertList(list)
        }
    
    }
    

    0 讨论(0)
提交回复
热议问题