-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: MultipleBagFetchException when using entity graph
PostPosted: Wed Jun 11, 2014 3:15 am 
Newbie

Joined: Wed Jun 11, 2014 3:04 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.