Hibernate version: 1.2.0
I've read the documentation on cascade options, and even read Ayende Rahien's explanation of them (
http://www.ayende.com/Blog/archive/2006/12/02/7065.aspx) but they're still not clear to me.
I still have these questions:
1. For one-to-manys, we always want this behavior:
1.1 Where entity A has collection property Bs and A is persistent, and a transient B is added to A.Bs, and back-referencing many-to-one property B.A is set to A, regardless of whether any (other) explicit changes have been made to A or not, when the session is flushed, then the transient B that was added should be inserted in the database.
1.2. Where entity A has collection property Bs and A is persistent, and a persistent B is removed from A.Bs, and back-referencing many-to-one property B.A is set to null, regardless of whether any (other) explicit changes have been made to A or not, when the session is flushed, then the persistent B that was removed should be deleted from the database if it has no other associations, otherwise B should be updated if other associations remain (since B.A was set to null).
Will all-delete-orphan give me this behavior?
2. For many-to-ones, assuming I have the foreign key delete cascade as "set null" in the database, where persistent entity A references entity type B through property A.B, and I call session.Delete(B) without explicitly setting A.B = null on all As in memory that are attached to the session, is there a cascade option that will set A.B = null on all the A instances in the session cache for me and update those as well, when I call flush?
3. For constrained one-to-ones, where persistent entity A references entity type B through property A.B, and A.B is set to null, is there any cascade option that will automatically delete B regardless of whether or not I set the back-referencing constrained property B.A to null, when the session is flushed? Or will it only be deleted if I set both forward and back references to null?