December 31, 2018
Android Room: room Entity class must be annotated with @Entity
If you run into the following error you probably provide a class that is either not correctly annotated or shouldn’t be there.
1 |
room Entity class must be annotated with @Entity |
The source of this problem usually can be found by looking at your database class, the example code is in Kotlin but should also apply to Java:
1 2 3 4 5 6 7 8 9 10 |
@Database(entities = arrayOf(User::class, Expense::class), version = 1) abstract class MyDatabase : RoomDatabase() { // --- DAO --- abstract fun userDao(): UserDao // --- DAO --- abstract fun expenseDao(): ExpenseDao } |
Now make sure, that any referenced class in the @Database
annotation in line 1 is annotated with @Entity
.