2017-10-13 64 views
2

當我在我的DAO類@Transaction註釋的方法,這是造成以下錯誤接收錯誤:房:使用@Transaction

A DAO method can be annotated with only one of the following:Insert,Delete,Query,Update

這裏是我的類:

@Dao interface Dao { 

    @Insert(onConflict = REPLACE) fun insertList(chacaras: List<String>) 

    @Query("SELECT * FROM chacara WHERE cityId = :cityId") 
    fun getListOfCity(cityId: String): LiveData<List<String>> 

    @Delete fun deleteList(chacaraList: List<String>) 

    @Transaction 
    fun updateList(list: List<String>){ 
     deleteList(list) 
     insertList(list) 
    } 

} 

當我刪除用@Transaction註解的方法時,它通常編譯。 有沒有辦法解決這個問題?

回答

4

按照transaction documentation

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

改變你類:

@Dao abstract class Dao { 

    @Insert(onConflict = REPLACE) abstract fun insertList(chacaras: List<String>) 

    @Query("SELECT * FROM chacara WHERE cityId = :cityId") 
    fun abstract getListOfCity(cityId: String): LiveData<List<String>> 

    @Delete abstract fun deleteList(chacaraList: List<String>) 

    @Transaction 
    open fun updateList(list: List<String>){ 
     deleteList(list) 
     insertList(list) 
    } 

}