0

At first, i know this is duplicate question but marked answer didn't solve the error.

I'm trying to create generic Dao interface within my Room Persistance Library following this guide but cannot solve error "Type of the parameter must be a class annotated with @Entity or a collection/array of it" for the generic T in GenericDao.

GenericDao:

@Dao
public interface GenericDao<T> {
    @Insert
    long insert(T object);

    @Update
    void update(T... objects);

    @Delete
    void delete(T... objects);
}

Inherited Dao:

@Dao
public abstract class ExerciseDao implements GenericDao<Exercise> {

    @Query("SELECT * FROM exercises")
    public abstract LiveData<List<Exercise>> getAllExercises();

}

Entity:

@Entity(tableName = "exercises",
    indices = {@Index(value = {"name"}, unique = true)})
public class Exercise {
    @PrimaryKey (autoGenerate = true)
     int id;

    @ColumnInfo(name = "name")
    private String name;

    @ColumnInfo(name = "muscle_part")
    private int musclePart;

    @ColumnInfo(name = "is_shown")
    private boolean isShown;

    public Exercise(String name, int musclePart, boolean isShown) {
        this.name = name;
        this.musclePart = musclePart;
        this.isShown = isShown;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMusclePart() {
        return musclePart;
    }

    public void setMusclePart(int musclePart) {
        this.musclePart = musclePart;
    }

    public boolean isShown() {
        return isShown;
    }

    public void setShown(boolean shown) {
        isShown = shown;
    }
}

I've tried:

  • Change GenericDao to abstract class.
  • Add/remove @Dao annotation in GenericDao
  • Add Generic Entity
  • Override methods in child Daos
  • ...

But always with the error. Has anyone an idea how to solve this problem?

Byro
  • 116
  • 5

0 Answers0