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: Merging Back to Transfer Object when using Session.merge
PostPosted: Thu May 07, 2009 7:33 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:32 am
Posts: 25
Location: Austria/Vienna
when using session.merge i would like to get the properties changed by the database merged back to the original input object of the merge method.
for example the generated id, the optlocking version or the changed-by information of my interceptor.

(the original input object should be used as the result for the GUI)

I failed to do this with any interceptor until now.

Is there a possible nice solution to do this with hibernate itself.

thanks!


Last edited by cgs on Thu May 07, 2009 11:11 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Merging Back to Transfer Object when using Session.merge
PostPosted: Thu May 07, 2009 10:54 am 
Newbie

Joined: Wed Jan 28, 2009 9:57 am
Posts: 16
Location: Leinfelden, Germany
I hope I've understood your question clearly.
The return value of the session.merge() is a persistent object, which is the merged entity. You can use this.
If you want to keep the same object passed as a param to the merge() then you may have to copy the attribute values from this persistent object to the passed object.
Hope this helps.


Top
 Profile  
 
 Post subject: Re: Merging Back to Transfer Object when using Session.merge
PostPosted: Fri May 08, 2009 11:17 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
Hi, mazhar is correct, but you shouldn't try to keep the old ref, until you make sure that you close the session or have evicted the returned object from the session.

Cause the return object by merge is a perfect copy, you should you use this until you really need JVM identity. (foo == bar)

Also keep in mind that merge doesn't keeps the contract at the moment on already deleted objects.

merge of a deleted object results in a insert

Greetings michael


Top
 Profile  
 
 Post subject: Re: Merging Back to Transfer Object when using Session.merge
PostPosted: Fri May 08, 2009 12:53 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:32 am
Posts: 25
Location: Austria/Vienna
hi urmech, mazhar.

as i sayed i <B>have to keep</B> the original input object as a master for the gui.

i know all the behaviours of merge... please stick to the question, and do not descirbe other things, because the thread gets unclear then...

now there are 3 ways to copy the information back to the original input object as far as i know:
1. do it manually
2. an interceptor (failed) ?
3. an event listener (still under research).

by the way. the reason i have to use the orignal object is that it is bound to a bad GUI framework which does currently not support successfull replacement of the reference to the merge result object.


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.