How do I write a one to many relationship where the many is a pojo of two other embedded entities? There may be multiple Bs for one A but only one B for one A per DataList.
Here is a simplification of my code.
@Entity(tableName = "as")
public class A{
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "a_id")
private int mId;
@ColumnInfo(name = "a_type")
private String mType;
//getters and setters
}
@Entity(tableName = "bs")
public class B{
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "b_id")
private int mId;
@ColumnInfo(name = "b_type")
private String mType;
@ColumnInfo(name = "list_id")
private int mListId;
//getters and setters
}
@Entity(tableName = "data_lists")
public class DataList{
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "data_list_id")
private int mId;
//getters and setters
}
public class AandB {
@Embedded
private A mA;
@Embedded
private B mB;
//getters and setters
}
public class DataListWithAandBs{
@Embedded
private DataList mDataList;
@Relation(
parentColumn = "data_list_id",
entityColumn = "list_id")
private List<AandB> mAandBList;
//getters and setters
}
@Dao
public interface DataListWithAandBsDao {
@Query("SELECT * FROM data_lists LEFT JOIN (SELECT * FROM as LEFT JOIN bs ON a_type = b_type) ON list_id = data_list_id")
LiveData<List<DataListWithAandBs>> getDataListsWithAsandBs();
}
When I compile I receive the error: The class must be either @Entity or @DatabaseView. I don't want the list to be an entity though I want it to be a list of Pojos. Is this possible to do with room?