I\'m new to Android Room. I want to read from a table and also read from a related table. The relationship is pretty common. One table defines instances. The other table defines
I solved that problem by adding prefix to column names so they are unique. If your case does not allow changing column names you should use some of the provided answers and @Embedded(prefix) annotation.
@Entity(tableName = "animal")
public class Animal {
@PrimaryKey
@ColumnInfo(name = "animal_id")
public long id;
...
}
@Entity(tableName = "animal_type")
public class AnimalType {
@PrimaryKey
@ColumnInfo(name = "animal_type_id")
public long id;
...
}
And your query will be:
SELECT * FROM animal JOIN animal_type ON animal_id = animal_type_id