Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Room: error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: abc)

I'd like to use the same kind of object to query multiple tables. I defined a base class like below:

@Entity
public class BaseWordId {
    @PrimaryKey
    @NonNull
    public Integer word_id;
}

I then subclassed the base class and also defined DAO for each of them.

@Entity(tableName = "abc")
public class ABC extends BaseWordId {
}

@Entity(tableName = "xyz")
public class XYZ extends BaseWordId {
}

@Dao
public interface ABCDao {
    @Query("SELECT * FROM abc")
    List<ABC> get_all();
}

@Dao
public interface XYZDao {
    @Query("SELECT * FROM xyz")
    List<XYZ> get_all();
}

But I kept getting a compile error that no such table: abc and no such table: xyz. Any idea?

like image 488
Apophis Avatar asked Sep 28 '18 11:09

Apophis


1 Answers

You should mention both the entities in your roomDatabase class.

@Database(entities = {BaseWordId.class, ABC.class}, version = VERSION_CODE, exportSchema = false) 
public abstract class YourDatabase extends RoomDatabase {
    //your Daos
}
like image 79
Santanu Sur Avatar answered Nov 14 '22 13:11

Santanu Sur