Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Room: Receiving error when using @Transaction

Tags:

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?

like image 745
Marcola Carr Avatar asked Oct 13 '17 12:10

Marcola Carr


1 Answers

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)     }  } 
like image 138
Marcola Carr Avatar answered Sep 28 '22 10:09

Marcola Carr