我正在为嵌套集合“无法同时获取多个包”。 这是实体和实体图定义的样子。 Hibernate版本:4.3.7 spring-data-jpa:1.8.1 “
@Entity
@Table(name = "ORGANISATION_GROUP")
@Where(clause = "IS_DELETED <> 1")
@NamedEntityGraphs(value = { @NamedEntityGraph(name = "onlyOrganisations", attributeNodes = { @NamedAttributeNode(value = "organisations", subgraph = "lightOrganisation") },
subgraphs = { @NamedSubgraph(name = "lightOrganisation", attributeNodes = { @NamedAttributeNode(value = "locations") }) }) })
public class OrganisationGroup implements Serializable{
private static final long serialVersionUID = 1L;
@Id
private Long id;
@ManyToMany()
@AuditJoinTable(name = "ORGANISATION_GROUP_MEMBER_AUD")
@JoinTable(name = "ORGANISATION_GROUP_MEMBER", joinColumns = @JoinColumn(name = "ORGANISATION_GROUP_ID", referencedColumnName = "ID"), inverseJoinColumns = @JoinColumn(
name = "ORGANISATION_ID", referencedColumnName = "ID"))
private List<Organisation> organisations = new ArrayList<>(0);
}
@Entity
@Table(name = "ORGANISATION")
public class Organisation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long id;
@Column(name = "name", length = 255, nullable = false)
private String name;
@OneToMany( mappedBy = "organisationId", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy(value = "location ASC")
private List<OrganisationLocation> locations;
}
@Entity
@Table(name = "ORGANISATION_LOCATIONS")
public class OrganisationLocation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long id;
@Column(name = "LOCATION")
private String location;
}
` 我尝试在location属性上使用@LazyCollection,但仍然得到相同的异常。但是,同样的事情在没有实体图并且将位置设置为fetch eager类型的情况下工作。如何使用实体图解决此错误?
答案 0 :(得分:2)
除非您有充分的理由不这样做,否则请尝试更改您的收藏集以使用Set
代替List
。