Error when use suspend function with room dao methods
See original GitHub issueI’m trying to make all database query / delete functions in the Dao class as suspend functions. I enabled kotlin coroutine in gradle, and add suspend keywork for all dao functions. Then build, and get errors for wrong param type for the auto generated dao methods.
In Dao class:
@Query("select * from myevent")
suspend fun all(): List<MyEvent> // I added the suspend keyword
@Delete
suspend fun deleteEvent(event: MyEvent)
...
Then build and get this error:
e: C:\Users\projectpath\app\build\tmp\kapt3\stubs\debug\com\robyn\myapp\data\source\local\EventsDao.java:39: error: Deletion methods must either return void or return int (the number of deleted rows).
public abstract java.lang.Object deleteEventById(@org.jetbrains.annotations.NotNull()
^
e: C:\Users\projectpath\app\build\tmp\kapt3\stubs\debug\com\robyn\myapp\data\source\local\EventsDao.java:41: error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.experimental.Continuation<? super kotlin.Unit> p1);
Error links navigate to code from the auto generated dao class:
...
@org.jetbrains.annotations.Nullable()
@android.arch.persistence.room.Delete()
public abstract java.lang.Object deleteAllEvents(@org.jetbrains.annotations.NotNull() // error indicates at this line
java.util.List<com.robyn.myapp.data.MyEvent> events, @org.jetbrains.annotations.NotNull()
kotlin.coroutines.experimental.Continuation<? super kotlin.Unit> p1); // error indicates at this line
...
I tried delete the generated dao class and rebuild to renegerate it, still get these errors. How can I fix this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Error with Room dao class when using Kotlin coroutines
In that case, if the suspend method isn't used in Dao, this activity will crash. It means that it is impossible to get...
Read more >When using suspend fun in Room Dao methods, following ...
When using suspend fun in Room Dao methods, following error: Not sure how to convert a Cursor to this method's return type (java.lang.Object)....
Read more >Kapt: "error: Type of the parameter must be a class annotated ...
This app uses the keyword "suspend" in the Dao (using Room). Feels like that keyword is crashing the program. I'll show the code...
Read more >Room Coroutines. Add some suspense to your database
DAO methods can now be marked as suspending to ensure that they are not executed on the main thread. Read on to see...
Read more >Kotlin flows on Android - Android Developers
For example, you can use a flow to receive live updates from a database ... As a suspend function cannot return multiple consecutive...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
where you able to resolve this issue? I have the same problems and can’t figure out a solution
@jcornaz I’m using Room Persistence library for Android. So now I’m using
suspend
not directly in the dao class but on its wrapper methods. Also I’ll try use it on the extension methods to avoid use it directly with@Query
, just as the example you provided. I think for improvement, the ide can give a red squiggly line when user try to usesuspend
together with Room’s@Query
annotation. Thank you for the examples!