0
我得到「不能同時獲取多個袋子」的嵌套收集。 以下是實體和實體圖定義的外觀。 Hibernate的版本:4.3.7 彈簧數據的JPA:1.8.1 'NamedEntityGraph:Hibernate投擲不能同時獲取多個袋子異常嵌套收集
@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;
}
` 我試圖用@LazyCollection上的位置屬性,但仍然得到同樣的異常。然而,同樣的事情沒有實體圖並且將位置設置爲獲取渴望類型。如何使用實體圖解決這個錯誤?
謝謝大衛。將所有集合更改爲Set後,我看不到任何問題。我無法理解的是爲什麼它只在使用實體圖時失敗? – Shashank