我对@OneToMany关系有些麻烦。 第一实体代表某种商品。
@Entity(name = "ARTIQULE")
public final class ArtiquleEntity extends CustomEntity{
@Id
@Column(name = "ID")
public Long id;
@NotNull
@Column(name = "METRIC_ID")
public Long metricId;
@NotNull
@Column(name = "STATUS_ID")
public Long statusId;
@NotNull
@Column(name = "NAME")
public String name;
@NotNull
@Column(name = "SHORT_NAME")
public String shortName;
@NotNull
@ManyToOne
@JoinColumn(name = "GROUP_ID")
public ArtGroupEntity artGroup;
}
其次是商品分组
@Entity(name = "AR_GROUP")
public final class ArtGroupEntity extends CustomEntity {
@Id
@Column(name = "ID")
public Long id;
@NotNull
@Column(name = "GROUP_ID")
public Long groupId;
@NotNull
@Column(name = "STATUS_ID")
public Long statusId;
@NotNull
@Column(name = "NAME")
public String name;
@NotNull
@Column(name = "L")
public Integer left;
@NotNull
@Column(name = "R")
public Integer right;
@NotNull
@OneToMany(mappedBy = "artGroup", fetch = FetchType.EAGER)
public List<ArtiquleEntity> artiquleEntities;
}
当我选择&#34;从AR_GROUP列表中选择列表&#34;。 Hibernate为每个组创建一个select,为什么它不使用外连接? 或者这是不可能的。
Hibernate: select artgroupen0_.ID as ID1_0_, artgroupen0_.GROUP_ID as GROUP_ID2_0_, artgroupen0_.L as L3_0_, artgroupen0_.NAME as NAME4_0_, artgroupen0_.R as R5_0_, artgroupen0_.STATUS_ID as STATUS_I6_0_ from AR_GROUP artgroupen0_
Hibernate: select artiquleen0_.GROUP_ID as GROUP_ID2_1_0_, artiquleen0_.ID as ID1_1_0_, artiquleen0_.ID as ID1_1_1_, artiquleen0_.GROUP_ID as GROUP_ID2_1_1_, artiquleen0_.METRIC_ID as METRIC_I3_1_1_, artiquleen0_.NAME as NAME4_1_1_, artiquleen0_.SHORT_NAME as SHORT_NA5_1_1_, artiquleen0_.STATUS_ID as STATUS_I6_1_1_ from ARTIQULE artiquleen0_ where artiquleen0_.GROUP_ID=?
Hibernate: select artiquleen0_.GROUP_ID as GROUP_ID2_1_0_, artiquleen0_.ID as ID1_1_0_, artiquleen0_.ID as ID1_1_1_, artiquleen0_.GROUP_ID as GROUP_ID2_1_1_, artiquleen0_.METRIC_ID as METRIC_I3_1_1_, artiquleen0_.NAME as NAME4_1_1_, artiquleen0_.SHORT_NAME as SHORT_NA5_1_1_, artiquleen0_.STATUS_ID as STATUS_I6_1_1_ from ARTIQULE artiquleen0_ where artiquleen0_.GROUP_ID=?
Hibernate: select artiquleen0_.GROUP_ID as GROUP_ID2_1_0_, artiquleen0_.ID as ID1_1_0_, artiquleen0_.ID as ID1_1_1_, artiquleen0_.GROUP_ID as GROUP_ID2_1_1_, artiquleen0_.METRIC_ID as METRIC_I3_1_1_, artiquleen0_.NAME as NAME4_1_1_, artiquleen0_.SHORT_NAME as SHORT_NA5_1_1_, artiquleen0_.STATUS_ID as STATUS_I6_1_1_ from ARTIQULE artiquleen0_ where artiquleen0_.GROUP_ID=?
感谢您的回复。
答案 0 :(得分:0)
答案 1 :(得分:0)
使用hql join fetch解决问题, 在我的选项中选择看起来像这样
from AR_GROUP list left outer join fetch list.artiqules