Atharv Vishwas Gupta
Atharv Vishwas Gupta

Reputation: 11

An abstract DAO method must be annotated with one and only one of the following annotations: Insert,Delete,Query,Update,RawQuery

@Dao
interface ArticleDAO {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun upsert(article: Article) : Long

    @Query("SELECT * FROM articles")
    fun getAllArticles(): LiveData<List<Article>>

    @DELETE
    suspend fun deleteArticles(article: Article)
}

Hi! On running this code, I get the following error: An abstract DAO method must be annotated with one and only one of the following annotations: Insert,Delete,Query,Update,RawQuery Please help me with this

Upvotes: 1

Views: 2183

Answers (3)

ahmnouira
ahmnouira

Reputation: 3431

I just forget to annotate the method with @Insert.

fun insertAll(postDbModels: Array<PostDbModel>)

Just adding @Insert fixed this.

@Insert
fun insertAll(postDbModels: Array<PostDbModel>)

Upvotes: 0

Tarif Chakder
Tarif Chakder

Reputation: 1856

You entered wrong annotation

replace

@DELETE

to

@Delete

Upvotes: 0

@JesúsBarrera from the comments is correct. check your imports. the annotation should be like this

@Delete

android studio will probably import this

import androidx.room.*

if not already present

Upvotes: 2

Related Questions