I have create a simple set of objects like:
Code:
class Parent{
...
@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
@OnDelete(action=OnDeleteAction.CASCADE)
@Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
public List<Child> getChildren() ..
...
}
class Child {
...
@ManyToOne()
@JoinColumn(name="PARENT_ID", nullable=false)
public Parent getParent()
...
@OneToMany(fetch=FetchType.EAGER, mappedBy = "configParam")
@OnDelete(action= OnDeleteAction.CASCADE)
@Cascade(value={CascadeType.ALL, CascadeType.DELETE_ORPHAN})
public List<GrandChild> getGrandChildren()
}
class GrandChild {
...
@ManyToOne()
@JoinColumn(name="CHILD_ID", nullable = false)
public Child getChild()
}
I then build a structure like:
--parent1
----child1
------grandchild1
------grandchild2
------grandchild3
(so, 1 parent, 1 child, 3 grandchildren)
Saving this structure works fine, and the db is correct. The issue is when I load a parent object it has
3 children instead of 1. Each child has the correct 3 grandchildren, but there should be only 1 child not 3.
The generated SQL looks fine, and there are 3 populated rows as you'd expect. I thought it might be an issue with .equals on the child, but I think it's fine....
Any help is greatly apprecitated!