-->
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: Taking care of Non-Nullable Fields in update()
PostPosted: Mon Aug 30, 2010 4:15 pm 
Newbie

Joined: Mon Aug 30, 2010 4:08 pm
Posts: 1
I am using the Update method of Hibernate to update a certain row.

I created my tablebean, populated it with the primary key, and then the secondary fields I want to change, and then executed the update:

TableBeanT newT = new TableBeanT();
newT.setID(..); // primary key
newT.setField1(..); // my update
getHibernateTemplate().update(newT);

The table also has some non-null columns. I didn't populate them in my bean, because I don't know/care what they are right now, I am not updating them.

However, Hibernate complains about inserting nulls into non-null columns. Is there a way to quickly save the non-null values of the existing bean and re-populate them into the new bean? Do I need to do a manual fetch before doing an update? Thanks


Top
 Profile  
 
 Post subject: Re: Taking care of Non-Nullable Fields in update()
PostPosted: Mon Aug 30, 2010 4:34 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
I don't know the Template thingy you are using (Spring?), but I can give a basic idea: Load the entity using the id, change the values you want to change and then flush the session (no need to call update, because the entity is still attached to the session and Hibernate tracks any changes).

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject: Re: Taking care of Non-Nullable Fields in update()
PostPosted: Tue Aug 31, 2010 1:28 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi NewToHibernate2010, "
Quote:
Where there is will there is a way
". There is way in hibernate too. You have to use your own user type. If this type is same across all the tables and its not null field, you can make values using user type.

<type name="userType">
<param name="get-default">no</param>
</type>

This parameter needs to be set using User Type class. dynami-insert="true" dynamic-update="true" in element class in mapping file.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


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.