I'm getting the following error:
error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
java.lang.String matchId);
on my matchedBefore()
query:
@Dao
interface MatchedUsersDao {
// Checks to see if user has matched before (if it returns 1)
@Query("SELECT COUNT(*) FROM matched_users WHERE :matchId = match_id LIMIT 1")
fun matchedBefore(matchId: String): Int
@Insert(onConflict = OnConflictStrategy.ABORT)
fun addMatchUid(matchId: String)
}
Here is my Entity
@Entity(tableName = "matched_users")
data class MatchedUser(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(name = "match_id") val matchId: String
)
DB
@Database(entities = arrayOf(MatchedUser::class), version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun matchedUsersDao(): MatchedUsersDao
}
and I instantiate my DB in my Application:
class CustomApplication : Application() {
companion object {
var database: AppDatabase? = null
}
override fun onCreate() {
super.onCreate()
CustomApplication.database = Room.databaseBuilder(this, AppDatabase::class.java, "AppDatabase").build()
}
Can someone tell me what the error is indicating and how I can solve it?
Your problem is this line
@Insert(onConflict = OnConflictStrategy.ABORT)
fun addMatchUid(matchId: String)
If you want use @Insert
annotations you must send instance of MatchedUser
not String.
So you can :
1) Send new MatchedUser
with your id (insert empty MatchedUser
with your id)
You code must be like this
@Insert(onConflict = OnConflictStrategy.ABORT)
fun addMatchUid(matchUser: MatchedUser)
2) Wrote new @Query
for inserting just id in db
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