-->
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: Why merge method creates copy of object
PostPosted: Tue Sep 08, 2015 7:19 am 
Newbie

Joined: Tue Sep 08, 2015 7:15 am
Posts: 3
This is pretty trivial question sorry for this, but I searched all over the internet but didn't get the answer for this.
Why a copy is required in merge method? why it do no persist the passed entity object directly? please help me with this?

Thank you


Top
 Profile  
 
 Post subject: Re: Why merge method creates copy of object
PostPosted: Wed Sep 09, 2015 4:47 am 
Newbie

Joined: Tue Sep 08, 2015 7:15 am
Posts: 3
krishna.atkalikar wrote:
This is pretty trivial question sorry for this, but I searched all over the internet but didn't get the answer for this.
Why a copy is required in merge method? why it do no persist the passed entity object directly? please help me with this?

Thank you

Isn't there any explanation for this?


Top
 Profile  
 
 Post subject: Re: Why merge method creates copy of object
PostPosted: Tue Sep 22, 2015 1:17 am 
Newbie

Joined: Tue Sep 08, 2015 7:15 am
Posts: 3
Consider a scenario I have a detached entity instance and if I fetch another row with same database identifier as like detached entity from database, so now I have a detached instance and a managed instance and both corresponds to the same database row. Now a if I try to merge the detached instance and instead of creating copy if the same detached instance is managed then it will leave managed instance in inconsistent state, i.e. a confusion is there about what needs to be done with the instance that is already there in Persistent context, so to avoid this merge method copies the state of detached instance and returns the managed instance.

This is fine but now this leads to a question why a transient instance is not managed directly, why a copy is needed in case of transient instance?


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.