-->
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: Is it possible to saveorupdate/merge like this?
PostPosted: Tue Dec 28, 2010 3:56 am 
Newbie

Joined: Fri Feb 05, 2010 1:05 am
Posts: 12
Hi every,

Let say the entity is already in DB and in the code I created a new instance with only some of the fields set (including the identifier). Is it possible to direct hiberate to update or merge only non-null fields to the persistent object? Since some fields are not set in the newly created object, they are set to null by hibernate. :/

Kindly Regards,
Quincy


Top
 Profile  
 
 Post subject: Re: Is it possible to saveorupdate/merge like this?
PostPosted: Tue Dec 28, 2010 8:11 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hibernate, or your own code if you would implement this directly, would need a way to understand what you did set, and what you did not define, so in both cases you should start by loading the original entity, and set the fields to be changed. Hibernate will then compare the old values with the new values, and perform the needed update statements.

So:
1) start a transaction
2) load the entity to be changed
3) apply changes on it
4) commit the transaction

If you also need the update statement to not rewrite unchanged fields/columns, search also for dynamic-update in the reference documentation.

_________________
Sanne
http://in.relation.to/


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.