-1

Actually I am clear with how to use inner jsonArray with Room persistence library. POJO class as follows:

@Entity(tableName = "customer")
public class CustomerResponseModel {
    @PrimaryKey
    @ColumnInfo(name = "version")
    @SerializedName("version")
    private int version;
    @ColumnInfo(name = "sync_date")
    @SerializedName("sync_date")
    private long syncDate;
    @Relation(parentColumn = "version", entityColumn = "customerId", entity = CustomerList.class)
    private List<CustomerList> customerList;
}

@Entity
public class CustomerList {
    @PrimaryKey
    @SerializedName("customer_id")
    private String customerId;
    @SerializedName("customer_type")
    private String customerType;
    @SerializedName("customer_name")
    private String customerName;
    @SerializedName("customer_addresses")
    @Relation(parentColumn = "customerId", entityColumn = "id", entity = CustomerAddress.class)
    private List<CustomerAddress> customerAddresses;
}

@Entity
public class CustomerAddress {
    @PrimaryKey(autoGenerate = true)
    private int id;
    @SerializedName("address")
    private String address;
    @SerializedName("contact")
    private String contact;
}

Error:(15, 8) error: Entities cannot have relations.

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
cyrus000
  • 67
  • 1
  • 9

1 Answers1

2

The issue appears because CustomerList class is an @Entity and inside of it you used the @Relation annotation. If you will remove the @Entity from that class the issue should disappear.

Check the official documentation from here

Note that @Relation annotation can be used only in Pojo classes, an Entity class cannot have relations.

Magda Miu
  • 21
  • 3