-->
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.  [ 5 posts ] 
Author Message
 Post subject: What does Session.saveOrUpdateCopy(Object) do?
PostPosted: Fri Feb 20, 2004 6:26 pm 
Could someone please explain to me what the new method Session.saveOrUpdateCopy(Object) does? I read the javadoc, but I don't understand what the real difference to Session.saveOrUpdate(Object) is and where this would be useful.

Thanks!


Top
  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The difference is that saveOrUpdateCopy will not attach the passed entity to the session in the case of update. Instead it will load the corresponding entity from the database and copy the values from the passed entity to the persistent one. The persistent instance is then returned.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 6:51 pm 
Thanks. Would you happen to know an example where this would be useful?


Top
  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 7:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Ummmmm, not off the top of my head :)

Maybe if it came from a different, still open session (like from another session factory)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 21, 2004 2:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
We don't think its useful and don't recommend it. It is there for the sake of completeness, since we now aim to be a "complete" ORM solution.

It *does* let you avoid the dreaded NonUniqueObjectException, but at the cost of performance.

(Actually NonUniqueObjectException is your friend. It tells you that you are risking possible loss of some changes, so in this sense saveOrUpdateCopy() is less "safe".)

It may also be used as an alternative to select-before-update if you are trying to avoid unnecessary SQL UPDATEs due to lack of a snapshot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.