【问题标题】:Android Room - Column conflict on entities that extend a classAndroid Room - 扩展类的实体上的列冲突
【发布时间】:2018-08-29 03:02:41
【问题描述】:

我有一个 Patient 实体,它扩展了一个基础 Resource 对象。现在Resource 包含一个uuid 和一个display,我也想将它们包含到患者表中,所以我这样注释:

public class Resource implements Serializable {

    @ColumnInfo
    protected String uuid;

    @ColumnInfo
    protected String display;

    // getters and setters
}

在我的Patient 实体中,有嵌套对象,它们也从Resource 扩展(例如PatientIdentifierPerson 对象被嵌入并具有自己的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
}

这会导致列名冲突 - 因为患者、PatientIdentifier 和 Person 有一个“uuid”列。

我想以嵌套对象的名称(例如“person_uuid”)重命名嵌套对象的 uuid 列,类似于实体关系中的 @ForeignKey 注释,请问我该怎么做?

【问题讨论】:

    标签: database entity android-room


    【解决方案1】:

    你可以这样指定列名:

    @ColumnInfo(name = "person_uuid")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多