Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting Room database "Invalid query argument" error while building project

I am using Room Database to store data in my application. But, trying to compile the project, I get the following error: "Invalid query argument". I tried to find the reason in the official documentation and also googling cause of this error, but it was all to no avail. Please, could you help by explaining what this error is in general, what causes it and what I need to fix in the project?

Exact error message

C:\Users\***\ParsedDatabase.java:10: error: Invalid query argument: int. It must be a class or an interface.
public final class ParsedDatabase {
             ^

Model – ParsedDatabase (Room Database entity, class with problem)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Entity(tableName = "parsed_database")
data class ParsedDatabase(
    @PrimaryKey()
    val id: Int = 1,
    @ColumnInfo(name = "app_config")
    val appConfigSection: HashMap<String, String>,
    @ColumnInfo(name = "loans")
    val loansList: ArrayList<Offer>,
    @ColumnInfo(name = "cards")
    val cardsList: ArrayList<ArrayList<Offer>>,
    @ColumnInfo(name = "credits")
    val creditsList: ArrayList<Offer>,
) {

    enum class AppConfigKeys {
        app_config,
        user_term_html,
        extra_field_,
    }

    enum class LoansAndCreditsKeys {
        loans,
        credits,
    }

    enum class CardsKeys {
        cards,
    }

}

Dao class (I attach just in case)

@Dao
interface LocalDatabaseDao {
    @Insert(onConflict = REPLACE)
    fun save(parsedDatabase: ParsedDatabase)

    @Query("SELECT * FROM parsed_database WHERE id = :id")
    fun load(id: Int = 1): ParsedDatabase?

    @Delete
    fun delete(parsedDatabase: ParsedDatabase)

    @Delete(entity = ParsedDatabase::class)
    fun delete(id: Int = 1)
}

Database class

@Database(entities = [ParsedDatabase::class], version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class LocalDatabase : RoomDatabase() {
    abstract fun getLocalDatabaseDao(): LocalDatabaseDao
}

>Solution :

    @Delete(entity = ParsedDatabase::class)
    fun delete(id: Int = 1)

I do not think that Room knows what to do with this. If you need that operation, you could try:

    @Query("DELETE FROM parsed_database WHERE id = :id")
    fun delete(id: Int = 1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading