我有一个 Patient
实体,它扩展了一个基础 Resource
对象。现在 Resource
包含一个 uuid
和一个 display
,我也想将其包含到 patients 表中,所以我这样注释:
public class Resource implements Serializable {
@ColumnInfo
protected String uuid;
@ColumnInfo
protected String display;
// getters and setters
}
在我的 Patient
实体中,有嵌套对象,它们也从 Resource
扩展(例如 PatientIdentifier
和 Person
对象是嵌入的并且有自己的 uuid 和显示):
@Entity(tableName = "patients")
public class Patient extends Resource implements Serializable {
@PrimaryKey
private Long id;
// ...
@Embedded
private PatientIdentifier identifier;
@Embedded
private Person person;
// other variables
}
这会导致列名冲突 - 因为 Patient、PatientIdentifier 和 Person 有一个“uuid”列。
我想在嵌套对象的名称后重命名其 uuid 列(例如“person_uuid”),类似于实体关系中的 @ForeignKey
注释,那么我可以知道该怎么做吗?
最佳答案
您可以像这样指定列名:
@ColumnInfo(name = "person_uuid")
关于database - Android Room - 扩展类的实体上的列冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52068875/