I am sorry for those who read this post. I forgot to mention something very important: there is of course a cascade on Child.element (that is why i do not understand the behavior of Hibernate).
Hi all,
I have a problem of cascading a relation many-to-one in a component. Syntactically, here is my classes:
Code:
public class Parent {
@CollectionOfElements(fetch = FetchType.LAZY)
@JoinTable(name = "parent_child"))
@IndexColumn(name = "position", base = 0)
private List<Child> children = new ArrayList<Child>();
....
}
@Embeddable
public class Child {
@ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@NotNull
private Element element;
...
}
public class Element {....}
When I try to persist a parent containing children which have all an element, I am expecting it will persist everything by cascading. In fact it returns me an exception TransientObjectException on the object element. The child cannot be persisted because it is linked to a transient entity (element of class Element) which is not persisted automatically => no cascade is happening on child.element :(
I am wondering if this is a limitation of the components or if this is a bug.
Thanks already for who might help :)
Tiggy