-->
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.  [ 3 posts ] 
Author Message
 Post subject: saveOrUpdateCopy() and merge() differences
PostPosted: Sun May 29, 2005 7:58 am 
Newbie

Joined: Sun May 29, 2005 7:45 am
Posts: 2
Hi all!
I need to persist a deeply nested object graph (5-6 levels). Objects in some levels could have been already persisted while others are new to the session. With hibernate 2.x I did a saveOrUpdateCopy() of the graph. According to the
migration guide I should do a merge() with hibernate 3.x. But the fact is that for cases as A--*B--*C (say, A is the parent of Bs which in turn are the parents of Cs, the relationships are all bidirectional associations and cascades=all...as in chaper 22) won't work. Because if B and C are new to the session, as B in not attached to it by merge(), hibernate will complaint that the (to-parent) reference from C to B is one to a non-persisted object.
How can I get the old saveOrUpdateCopy() behaviour back?
Thank you in advance.
Regards,
Carlos


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 4:55 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
I would think that "saveOrUpdate" should work fine... Are these detached objects or are have all been loaded in the same session?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 9:28 pm 
Newbie

Joined: Sun May 29, 2005 7:45 am
Posts: 2
For some of them there are previous persistant instances attached with the session so saveOrUpdate() will fail. Other are completely new to the session (the instances were created but never persisted yet). So cascading merge() will fail for other objects which refer to these (for example their children in a bidirectional parent-child relationship). So I see no way to take the root of the graph and persist the entire graph via cascading. I did this with saveOrUpdateCopy() in hibernate 2.x. But even the behaviour of saveOrUpdateCopy() in the 2.x-compatibility Session interface provided by hibernate 3.x differs from that of the original 2.x Session (it fails in the same way that merge() does). So for now I'm downgrading to 2.x and it works fine. But eventually I would like to migrate to 3.x.
Regards,
Carlos


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.