I have the following parent/child relations:
Code:
ClassA
/ \
ClassB ClassC
\ /
ClassD
Relations from top to bottom are all one-to-many. A has many Bs, A has many Cs, and both B and C have many Ds. D basically implements a many-to-many between B and C.
All associations are bi-directional. For all one-to-many
set mappings, I have
cascade="all-delete-orphan". For all
many-to-one mappings, I have no cascade defined and
not-null="true". In other words, all children must have a parent, and all operations cascade from parents to children.
The problem is I can't create a simple four object graph and save it. When I call
saveOrUpdate on an object of
ClassA, I get the following exception:
Code:
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: com.mycompany.ClassD.objectC
I assume this happens because Hibernate tries to persist the ClassD object before the ClassC object. How can I make this work? Isn't Hibernate supposed to correctly order saves so this doesn't happen? I am using version 2.1.6.
Thanks.