-->
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.  [ 4 posts ] 
Author Message
 Post subject: what is the technical difference between Merge and persist
PostPosted: Tue Apr 19, 2011 12:23 am 
Newbie

Joined: Thu Apr 07, 2011 6:38 am
Posts: 8
Hi
What exactly the difference between merge() and persists(). As my "detached entity persist error" is solved by using merge in steaded
of persists()


Top
 Profile  
 
 Post subject: Re: what is the technical difference between Merge and persist
PostPosted: Tue Apr 19, 2011 3:31 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 3:31 am
Posts: 41
In case anybody finds this thread...

persist() is well defined. It makes a transient instance persistent. However, it doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time. The spec doesn't say that, which is the problem I have with persist().

persist() also guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries. This is useful in long-running conversations with an extended Session/persistence context.

A method like persist() is required.

Update and Merge both work on detached instances, ie instances which have a corresponding entry in the DB but which are currently not attached to (or managed by) a Session. The difference between them are what happens to the instance which is passed to the function. update tries to reattach the instance, that means that there may be no other instance of the persistent entity attached to the Session right now otherwise a exception is thrown. merge, however, just copies all values to a persistent instance in the Session (which will be loaded if it is not currently loaded). The input object is not changed. So merge is more general than update, but may use more resources.

_________________
Thanks
Niki


Top
 Profile  
 
 Post subject: Re: what is the technical difference between Merge and persist
PostPosted: Thu Apr 21, 2011 12:14 am 
Newbie

Joined: Thu Apr 07, 2011 6:38 am
Posts: 8
Hi
I am using persist method to save and merge method to update in my
DAO layer and I am using
@Transactional(readOnly=true) annotation in my every save method
but still i am getting the detached entity passed to persist error

please help
thank you


Last edited by manojpal17 on Fri Aug 19, 2011 6:39 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: what is the technical difference between Merge and persist
PostPosted: Thu Apr 21, 2011 12:16 am 
Newbie

Joined: Thu Apr 07, 2011 6:38 am
Posts: 8
Hi Niki
thanks for your suggestion
bye


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