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 following:Insert,Delete,Query,Update
Here's my class:
@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) } }
When I remove the method annotated with @Transaction it compiles normally. Is there anyway to fix this?
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) } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With