我有一个名为" config"的实体,在其中我有一个主键和使用@Embedded批注嵌入到其中的另一个实体的列表。
@Entity(tableName = "config")
public class ConfigModules {
@PrimaryKey
@ColumnInfo(name = "id")
private Long id;
@JsonProperty("modules")
@Embedded
private ArrayList<ConfigModuleEntity> modules;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ArrayList<ConfigModuleEntity> getModules() {
return modules;
}
public void setModules(ArrayList<ConfigModuleEntity> modules) {
this.modules = modules;
}}
以上嵌入式注释ConfigModuleEntity如下所示:
@Entity(tableName = "config_module")
public class ConfigModuleEntity {
@JsonProperty("id")
@ColumnInfo(name = "module_id")
private String moduleId;
@JsonProperty("isConfigSupported")
@ColumnInfo(name = "isConfigSupported")
private int isConfigSupported;
@JsonProperty("subModules")
@Embedded
private ArrayList<ConfigSubModuleEntity> subModules;
public String getModuleId() {
return moduleId;
}
public void setModuleId(String moduleId) {
this.moduleId = moduleId;
}
public int getIsConfigSupported() {
return isConfigSupported;
}
public void setIsConfigSupported(int isConfigSupported) {
this.isConfigSupported = isConfigSupported;
}
public ArrayList<ConfigSubModuleEntity> getSubModules() {
return subModules;
}
public void setSubModules(ArrayList<ConfigSubModuleEntity> subModules) {
this.subModules = subModules;
}}
因此,在创建表时,我们需要只指定父实体,房间数据库会自动创建子表,还是需要为每个实体创建表?