-->
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: EJB3/JPA Entended Persistence Context and merge()
PostPosted: Mon May 14, 2007 12:04 pm 
Beginner
Beginner

Joined: Fri Jul 28, 2006 12:01 pm
Posts: 21
This is kind of a general question but...
Is there ever a need to merge an entity when using an Extended Persistence Context? I guess the overarching question is do entities ever become detached in an extended pc? Being new to EJB3/JPA I am having trouble conceptualizing when to use persist() vs using merge(). I know that persist is usually thought of as an sql INSERT and merge is usually thought of as an sql UPDATE but does merge() ever call an INSERT when creating a new entity? Are merge() and persist() interchangeable when dealing with new entities (or are they ever interchangeable)?

Thanks for any help.

-Brian


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can use merge instead of persist to make a transient entity persistent
Code:
Entity persistentE = em.merge(e);

persist is probably going to be more efficient though

you cannot persist() a detached object, so the 2 operations are not interchangeable.

An EPC is useful whithin a user conversation, if you want to reattach object in between different conversations, then merge makes sense even in an XPC.

_________________
Emmanuel


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.