Hi,
I'm having a similar problem, and chapter 16 of the Hibernate docs doesn't seem to relate all that well. We're using Hibernate in a large project, and are in the process of cleaning up/optimizing the mapping file. We are running Hibernate 2.1.6, on Oracle.
We have:
- parent doesn't reference children
- child class references one parent (many-to-one)
- child class has mutable='false'
- child -> parent relationship has cascade='save-update'
- child -> parent relationship has not-null='true'
- both child and parent are unsaved
We are working in a transaction.
What seems to happen is that Hibernate writes the child class first, but the link to parent is null (because parent doesn't have an id yet). It then (I assume) writes the parent, generates its id, then updates the child.
This, of course, causes problems with the not-null on the child mapping. If we take out the not-null, then the database becomes inconsistent -- Hibernate doesn't update the child with the parents ID, presumably because the child is supposed to be immutable. So that's even more of a problem.
Basically, we want the relationship to be not-null, and for the child objects to be immutable -- that's the way it should be, for our design.
Is there any way we can get around this, just using Hibernate (not recoding our own cascade solution)?
Regards
Simon Russell
|