-->
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: Are they same? save=persist, update=merge, delete=remove
PostPosted: Mon May 05, 2008 12:08 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

I'm just switching from Hibernate Core to JPA but still a bit uncertain with persist() & merge(). For remove(), I'm quite sure it's equivalent.

Are the following understanding correct?

Hibernate's Session.save() is same as JPA'S EntityManager.persist()
Hibernate's Session.update() is same as JPA'S EntityManager.merge()
Hibernate's Session.delete() is same as JPA'S EntityManager.remove()

Please advise.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 6:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I guess that's a good working assumption. However, there are differences for example in the return types of these methods.

The hibernate entity manager documentation says:

Quote:
Merging in EJB3 is similar to the saveOrUpdateCopy() method in native Hibernate. However, it is not the same as the saveOrUpdate() method, the given instance is not reattached with the persistence context, but a managed instance is returned by the merge() method.


I recommend reading through the entity manager documentation and looking at the examples there.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 5:59 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Also note that although these methods have similar behavior, they cascade separately. So if you have cascade="save", and you persist() something, that action will not be cascaded. Definitely check out the EM reference, as Hardy suggested. Pay particular attention to merge().

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.