Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Room - Column conflict on entities that extend a class

I have a Patient entity which extends a base Resource object. Now Resource contains a uuid and a display, which I also want to include to the patients table, so I annotate like so:

public class Resource implements Serializable {

    @ColumnInfo
    protected String uuid;

    @ColumnInfo
    protected String display;

    // getters and setters
}

And in my Patient entity, there are nested objects and they also extend from Resource (e.g. a PatientIdentifier and a Person object is embedded and has their own uuid and display):

@Entity(tableName = "patients")
public class Patient extends Resource implements Serializable {

    @PrimaryKey
    private Long id;

    // ...

    @Embedded
    private PatientIdentifier identifier;

    @Embedded
    private Person person;

    // other variables
}

this results in a column name conflict - as there is a "uuid" column for a Patient, the PatientIdentifier and the Person.

I want to rename the nested objects' uuid columns after their name (e.g. "person_uuid"), similar to the @ForeignKey annotation in entity relationships, so may I know how to do that?

like image 536
Fawwaz Yusran Avatar asked Nov 04 '25 20:11

Fawwaz Yusran


1 Answers

You can specify the column name like that :

@ColumnInfo(name = "person_uuid")
like image 190
K. Rachid Avatar answered Nov 07 '25 16:11

K. Rachid