-->
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 existing recored hibernate using
PostPosted: Mon Oct 13, 2008 1:11 pm 
Newbie

Joined: Sun Oct 12, 2008 11:15 pm
Posts: 4
All,
I have a required for updating the exisitng data, Please suggest how can I do that.
I have mapped bean to table.

As of now I am using this but I guess there should be better way of doing this


Query query3 = s.getNamedQuery(FaceBookConstants.UPDATEADDRESSPROFILE_QUERY);
query3.setString("newstreetAddress1",addressInfoVO.getStreetAddress1());
query3.setString("newstreetAddress2",addressInfoVO.getStreetAddress2());
query3.setString("newcity",addressInfoVO.getCity());
query3.setString("newstate",addressInfoVO.getState());
query3.setString("newzip",addressInfoVO.getZip());
query3.setString("newcountry",addressInfoVO.getCountry());
query3.setString("newlandlinePhone",addressInfoVO.getLandlinePhone());
query3.setString("newcellPhone",addressInfoVO.getCellPhone());
query3.setString("newProfileId",profileId);
int rowCount3 = query3.executeUpdate();


<query name="UPDATE_ADDRESSPROFILE">
<![CDATA[update AddressInfoBean set streetAddress1=:newstreetAddress1,streetAddress2=:newstreetAddress2,
city=:newcity,state=:newstate,zip=:newzip,country=:newcountry,landlinePhone=:newlandlinePhone,
cellPhone=:newcellPhone where profileId = :newProfileId]]>
</query>

Thanks
!techbyte


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 2:53 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Yes.
Provided that addressInfoVO is of the same class as your mapped bean class, male sure that it has the same ID and call

Code:
session.merge(addressInfoVO)


That will overwrite he row with new values in addressInfoVO.

_________________
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.