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