Let's say I have a persistent object of class A and B. There is an unidirectional relation from A to B as a property. And there is also an independant unidirectional relation from B to A as a property. I would like the relations to have a not-null constraint (and a unique constraint on on of the relation).
The problem is that after creating A or B and setting the relations to eachother I cannot make either A or B persistent, because Hibernate complains that there is a null or transient propery. Which is true, because when I save A there is a property to B which is not persistent yet. And when I save B there is a propery to A which is not persisten yet. It's like the chicken or the egg problem.
So is there something I can about this besides dropping the constraints? And setting one the relations after making the objects persistent? Is there for example a possibility to make two objects persistent at the same time?
|