-->
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: Update Detatched Object But Ignore nulls
PostPosted: Wed Jan 27, 2010 7:01 pm 
Newbie

Joined: Mon Jun 05, 2006 11:44 am
Posts: 11
Here's my scenario:

1) Class A is JPA annotated and configured as a persistable class in Hibernate
2) In my flow, I have an instance of A which was created outside Hibernate. Its NON-NULL fields represent fields that need to be updated.
3) I want to update A's values in the database but I want to ignore null values of A (ie: the update shouldn't set things to null)

I've read up on merge(), saveOrUpdate(), and @org.hibernate.annotations.Entity(selectBeforeUpdate = true, dynamicUpdate = true).

It seems like I want to do some combination of calling merge() along with annotating A with @Entity(dynamicUpdate = true).

What I'm really trying to avoid here is having to write a whole bunch of ifs for every field in A to determine which non-null fields need to be updated.

What is the proper way to do this?


Top
 Profile  
 
 Post subject: Re: Update Detatched Object But Ignore nulls
PostPosted: Thu Jan 28, 2010 5:07 pm 
Newbie

Joined: Mon Jun 05, 2006 11:44 am
Posts: 11
<bump />

Anyone have any insight on this?


Top
 Profile  
 
 Post subject: Re: Update Detatched Object But Ignore nulls
PostPosted: Thu Jan 28, 2010 7:34 pm 
Newbie

Joined: Fri Feb 09, 2007 1:47 pm
Posts: 4
Sorry I don't have a solution but I am looking for the exact same thing. I'm trying to implement a generic REST end point for PUT calls. The only problem with this that i can think of is the problem that you describe above.

Anyone have ideas?

Chris


Top
 Profile  
 
 Post subject: Re: Update Detatched Object But Ignore nulls
PostPosted: Mon Feb 22, 2010 11:17 am 
Newbie

Joined: Wed Jun 17, 2009 6:02 am
Posts: 4
Hi,

i'm also looking for a solution to ignore null-values in an update query. the dynamicUpdate settings, as already mentioned, only updates unmodified values. if a value of my dom object is null, it interprets this as a change :((. so we basically need a critera to be set for this attribute, that it is ignored in an update statement if it is null. i couldn't find a proper solution until now, so i'm also
very interested if someone know how to do it properly.

thx!

greetings,
bens0n


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.