database - Android Room - 扩展类的实体上的列冲突

标签 database entity android-room

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

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
}

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

我想在嵌套对象的名称后重命名其 uuid 列(例如“person_uuid”),类似于实体关系中的 @ForeignKey 注释,那么我可以知道该怎么做吗?

最佳答案

您可以像这样指定列名:

@ColumnInfo(name = "person_uuid")

关于database - Android Room - 扩展类的实体上的列冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52068875/

相关文章:

c++ - 具有大量数据的类型安全实体对象

.net - 循环引用和 WCF

android - 当 Room 没有 LiveData 而不是从 REST API 获取时返回 LiveData 的存储库

Android kapt java.lang.UnsatisfiedLinkError 房间

php - 数据库、代码(php)、安全测试工具

mysql - 需要帮助优化外连接 SQL 查询

java - 在 Java 中连接到 MySQL 数据库时访问被拒绝

ruby-on-rails - 在 Rails 应用程序中减少数据库查询的技术

c# - 用于实现 "Search as you type"Combobox 的 BackgroundWorker

android - Android ROOM保存Map <String,Object>