-->
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: Update the partial java object through merge
PostPosted: Fri Oct 03, 2008 10:08 am 
Newbie

Joined: Fri Oct 03, 2008 9:32 am
Posts: 2
Hi

From the presentation layer i am sending the partial java object where i am changing only one or two elements (i know the id or key). When i try to do session.merge() on the partial object, my understanding is if there is no persistent instance currently associated with the session, try to load it from the database and merge with the object i am passing.

The object which i am trying to update has both parent and child relations. After the merge i am loosing all the relations and only updating the fields which sets in the java object.

Question is there a way i can update the partial object and preserve all the relations or i have to pass the whole object (with relations) when i do merge. Any inside is of great help.


Regards
Rishi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2008 12:54 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Rishi,

First of all, read this

http://hibernar.org/articulos_en/persis ... ethods.php

(especially the part that describes what merge() does).

What you are trying to do, is some sort of "code repository style" merge, Hibernate is not designed to do that. How can Hibernate know what properties and/or collection items you want to keep, or to when interpret it as an overwrite?

You will have to resolve that "merging" algorithm yourself, according to your needs, most likely by first retrieving the current object, and then comparing it with the new information you want to persist.

_________________
Gonzalo Díaz


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.