These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cascade options confusion
PostPosted: Wed Jul 18, 2007 4:02 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.