-->
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: looking for suggestions
PostPosted: Wed Aug 27, 2008 1:43 am 
Newbie

Joined: Sat Jul 07, 2007 4:54 am
Posts: 2
hi all. i have scenario where im trying to do an unconventional table update and need some help.

i have a table 'contacts' with a mapped java class 'Contact'. for everything else im letting hibernate handle by passing or retrieving a Contact object and everything is working great. however.. im now being asked to make some changes where users will be updating individual fields in the application. in this scenario i wont have a Contact object with values but instead just a single field and its new value (for example 'address' and '1234 HBN lane') along with the contact's id.

im trying to determine the best way to go about making updates to individual fields. i thought of adding a sql-update entry with native SQL to my mapping file but the problem with that is i wont know which field is being updated. i cant do a 'update contacts set ? = ? where ...' so that wont work.

any thoughts on how to best get this done? if it were up to me the app wouldnt work like this but its not so im kind of forced to work with what i have been given. any idea's are greatly appreciated.

thanks
K


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2008 4:55 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can use a dynamically created query. Something like this:

Code:
Session session = ....
Query query = session.createQuery("update Contact c set c.address = :address where c.id = :id");
query.setParameter("address", "1234 HBN lane", Hibernate.STRING);
query.setParameter("id", theId, idType);
query.exexcuteUpdate();


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.