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?
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
}
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