Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

org.hibernate.HibernateException: cannot simultaneously fetch multiple bag

843830Feb 29 2008 — edited Nov 28 2008
I have the following object graph.

Parent------> Child---->GrandChild

Parent has OneToMany relation with Child and Child has ManyToOne back to Parent (Bi-directional)

Child has OneToMany relation with GrandChild and GrandChild has ManyToOne back to Child(Bi-directional)

I am trying to Eager Load the entire Object Graph. I was able to CASCADE persist the entire tree.


My Entities:
-----------------
 @Entity
           @Table (name = "PARENT", schema = "TEST")
           public class Parent {
 
            ....
           //Paremt has collection of children
           private Collection<Child> children = new ArrayList<Child>();
 
           ...
           @OneToMany (cascade=CascadeType.ALL, fetch=FetchType.EAGER,  mappedBy="parent")
           public Collection<Child> getChildren() {
		return children;
	    }
 @Entity
           @Table (name = "CHILD", schema = "TEST")
           public class Child {
           private int cid;
           // private int pareintId; (removed it)
  
           //Ref back to parent 
	   private Parent parent;
           
	   // Coll of GrandChildren
	   private Collection<GrandChild> grandchildren = new ArrayList<GrandChild>();
 
           //acccessor methods
	   .....

           @ManyToOne
	   @JoinColumn(name="PARENT_ID")

           //
	   @OneToMany (cascade=CascadeType.ALL, fetch=FetchType.EAGER,  mappedBy="child")
           public Collection<Child> getGrandChildren() {
		return grandchildren;
           }
           @Entity
           @Table (name = "GRAND_CHILD", schema = "TEST")
           public class GrandChild {
           private int gcid;
           
           //Ref back to parent 
	   private Child child;
           
	   
           //acccessor methods
	   .....

           @ManyToOne
	   @JoinColumn(name="CHILD_ID")
           
While deploying into Jboss server, it gives the following exception:

  Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 26 2008
Added on Feb 29 2008
3 comments
758 views