我从Hibernate 3迁移到了Hibernate5。我遇到了下一课的问题。当休眠填充对象OrderStatus时,它将生成下一个SQL
select
fieldsacce0_.status_code as status_c1_78_0_,
fieldsacce0_.fieldsAccess1_status_code as fieldsAc5_78_0_,
fieldsacce0_.fieldsAccess1_field_code as fieldsAc6_78_0_,
fieldsacce0_.field_code as field_co2_0_,
agentsfiel1_.status_code as status_c1_78_1_,
agentsfiel1_.field_code as field_co2_78_1_,
agentsfiel1_.is_editable as is_edita3_78_1_,
agentsfiel1_.is_visible as is_visib4_78_1_,
agentfield2_.code as code1_77_2_,
agentfield2_.name as name2_77_2_
from
zusb_agent_fields_access fieldsacce0_
inner join
zusb_agent_fields agentfield2_
on fieldsacce0_.field_code = agentfield2_.code
inner join
zusb_agent_fields_access agentsfiel1_
on fieldsacce0_.fieldsAccess1_status_code = agentsfiel1_.status_code
and fieldsacce0_.fieldsAccess1_field_code = agentsfiel1_.field_code
where
fieldsacce0_.status_code =?
我不明白为什么Hibernate添加fieldsAccess1_? 我花了很多时间,看到了像it这样的例子。我看不到示例和代码之间的区别。我希望任何人都有一个主意。 附言我为我的英语感到很抱歉
public class AgentFields implements Serializable {
private static final long serialVersionUID = 1929364703157730060L;
@Id
@Column(name = "code", length = 50)
private String code;
@NotNull
@Column(name = "name", columnDefinition = "nvarchar2(255)")
private String name;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@Table(name="zusb_agent_fields_access")
@Embeddable
public class AgentsFieldAccess extends FieldAccess {
private static final long serialVersionUID = -198576118682083784L;
@Id
@Column(name = "status_code")
private String statusCode;
@Id
@Column(name = "field_code")
private String fieldCode;
@Column(name = "is_visible", columnDefinition = "number(1, 0)")
private boolean visible;
@Column(name = "is_editable", columnDefinition = "number(1, 0)")
private boolean editable;
@Override
public boolean isVisible() {
return visible;
}
@Override
public void setVisible(boolean visible) {
this.visible = visible;
}
@Override
public boolean isEditable() {
return editable;
}
@Override
public void setEditable(boolean editable) {
this.editable = editable;
}
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public String getFieldCode() {
return fieldCode;
}
public void setFieldCode(String fieldCode) {
this.fieldCode = fieldCode;
}
}
@Table( name = "zusb_agent_statuses")
@Entity
public class OrderStatus implements Serializable {
@ElementCollection(targetClass = AgentsFieldAccess.class)
@CollectionTable(name = "zusb_agent_fields_access", joinColumns = { @JoinColumn(name = "status_code", referencedColumnName = "code") })
@MapKeyJoinColumn(name = "field_code")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Column(name = "fields_access")
private Map<AgentFields, AgentsFieldAccess> fieldsAccess1 = new HashMap<AgentFields, AgentsFieldAccess>();
}