Hi,
I experience some strange behaviour when I try to eagerly fetch two relations that I defined as lists.
It works perfectly fine to load the entity with a normal query, but as soon as I try to use an entity graph,
I get an exception: MultipleBagFetchException: cannot simultaneously fetch multiple bags
So, my question is: why does this happen and how can I fix it?
My entity looks like this:
Code:
@Entity
@NamedEntityGraph(name = "Person.loadAll",
attributeNodes = {
@NamedAttributeNode(value = "managedPersons", subgraph = "personName"),
@NamedAttributeNode(value = "incidents", subgraph = "incidentNumber")},
subgraphs = {
@NamedSubgraph(name = "personName",
attributeNodes = {
@NamedAttributeNode("name")
}),
@NamedSubgraph(name = "incidentNumber",
attributeNodes = {
@NamedAttributeNode("number")
})
})
public class Person {
private long id;
@ManyToOne
@JoinColumn(name = "managerid")
private Person manager;
@OneToMany(mappedBy = "manager", fetch = FetchType.EAGER)
@OrderBy("name ASC")
private List<Person> managedPersons;
@OneToMany(mappedBy = "caller", fetch = FetchType.EAGER)
@OrderBy("number ASC")
private List<Incident> incidents;
//some more stuff...
}
I'm using hibernate version 4.3.5.
Cheers,
Anna