-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to disable cascade delete or update programmatically
PostPosted: Wed Jun 28, 2006 11:30 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Hi all,

I am working with a entity graph. My A entity class contains sets of B which contains sets of C.

Mapping : All of this is mapped birectionnally (<set ...> in the parent with cascade="all,delete-orphan", <many-to-one ...> in each child).

I modified a property of B. So I call
Code:
Session.update(myInstance);
to update the B class.

The thing is : I'm working one copies of entities. So there's no way to detect the changes (i.e. I'm not working with proxified objects) that have been done.

I know that the method I'm coding will actually only affect fields of B class, none of the parent one (A) or one of the children (in the C set).

So in this method, I'd like to be able to disable the cascade mode and set it for this time to cascade="none" to be sure that the update will only affect the B table.

In fact, without doing it, because my object is a copy of the old retrieved B entity, when I update the B object, an update is called for each of the C element 'cause H3 can't know it has changed or not and the cascade mode is "all,delete-orphan"...

To sum up : is there a method to temporarily disable cascading ? Like the setFetchMode() method can change the default lazy behaviour given in the hbm files ?

Thanks a lot.

Hibernate version: 3.1.1

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 6:10 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No, I don't think so. But there is a nifty workaround that I use. Change the cascade in your mapping to be explicit about the cascade ops: use cascade="save,merge,update,delete,delete-orphan" etc. etc., but leave out cascade mode "replicate". Then when you save your (detached) copy object, don't attach it first, save it using replicate (ReplicationMode.OVERWRITE). And it won't cascade. When you want the cascade, just reattach the object, then save in the normal fashion.

_________________
Code tags are your friend. Know them and use them.


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

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.