Java 房间数据库实体初始化

Java 房间数据库实体初始化,java,android,mvvm,android-sqlite,android-room,Java,Android,Mvvm,Android Sqlite,Android Room,我们有以下Json和模型类。如何在此Json上启动Room实体数据库 { "ResultResponse": "Success", "OTPValue": "3239", "EmployeeInfo": [ { "EmployeeCode": "EMP001", "Name": "Natheem", "ContactNo": "9952265503", "

我们有以下Json和模型类。如何在此Json上启动Room实体数据库

   {
    "ResultResponse": "Success",
    "OTPValue": "3239",
    "EmployeeInfo": [
        {
            "EmployeeCode": "EMP001",
            "Name": "Natheem",
            "ContactNo": "9952265503",
            "AlternativeContactNo": "9952265502",
            "Age": "22",
            "DOB": "1995-10-08T00:00:00",
            "ImagePath": "C:\\FaceTag\\FaceTag\\Images\\EMP001\\natheem.jpg",
            "Latitude": "1.104492000000000e+001",
            "Longitude": "7.701183000000000e+001",
            "Address1": "45, Bharathiyar Nagar",
            "Address2": "Coimbatore",
            "City": "Coimbatore",
            "State": "Tamilnadu",
            "Country": "India",
            "Zip": "641001",
            "IsSupervisor": false,
            "FormId": 0
        }
    ],
    "AdditionalField": null,
    "FieldControl": null
}
我的实体类是

  @Entity(tableName = "tbl_device_register")
public class DeviceRegister {


    @PrimaryKey(autoGenerate = true)
    private int id;

    @SerializedName("ResultResponse")
    @Expose
    private String resultResponse;
    @SerializedName("OTPValue")
    @Expose
    private String oTPValue;
    @SerializedName("EmployeeInfo")
    @Expose
    private List<EmployeeInfo> employeeInfo = null;
    @SerializedName("AdditionalField")
    @Expose
    private Object additionalField;
    @SerializedName("FieldControl")
    @Expose
    private Object fieldControl;
@实体(tableName=“tbl\U设备\U寄存器”)
公共类设备注册器{
@PrimaryKey(自动生成=真)
私有int-id;
@SerializedName(“ResultResponse”)
@暴露
私有字符串resultResponse;
@SerializedName(“OTPValue”)
@暴露
私有字符串oTPValue;
@SerializedName(“EmployeeInfo”)
@暴露
私有列表employeeInfo=null;
@SerializedName(“附加字段”)
@暴露
私有对象附加字段;
@SerializedName(“FieldControl”)
@暴露
私有对象控制;
如何分配外键,以及如何处理表关系。大多数教程都是关于基础知识的。谢谢

添加ForeignKey意味着我们在该实体和 在这个参数中,我们声明parentColumns,它是 User类和childColumns中id列的名称,它是 Repo类中用户id列的名称

外键结构为

@Entity(foreignKeys =
    [
        ForeignKey(
                entity = SOURCECLASSNAME::class,
                parentColumns = arrayOf("id"),
                childColumns = arrayOf("id"),
                onDelete = ForeignKey.CASCADE
        )
    ], indices = [Index(value = "id")]
)
确保在下面导入

import static android.arch.persistence.room.ForeignKey.CASCADE;
你可以阅读