-->
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: How to update only the selected fields
PostPosted: Wed Aug 03, 2005 12:18 am 
Beginner
Beginner

Joined: Mon Jul 25, 2005 12:35 am
Posts: 24
Location: Sri Lanka
Hi,
I'm going to update a table raw new data. POJO class (i.e SystemUser) correcsponds to that table contains 5 fields. I want to update only 2 of them. I follow following way to update it...

public void updateSystemUser(SystemUser systemUser){
session.update(systemUser);
....commitTransaction();
}

In here for the systemUser object I have set those 2 fields only and other fields I havent set.
In this case database table raw has updated but values of other 3 fields become empty... I dont want to reset those 3 fields abd I want to keep values of those 3 fields as it is..

How can I solve this problem?

Really appreciate your help..

Thank you.
Thilina.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 12:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
try a "bulk update" (its in the docs)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 2:58 am 
Beginner
Beginner

Joined: Mon Jul 25, 2005 12:35 am
Posts: 24
Location: Sri Lanka
I have use following and it will do the job correctly...

public void updateSystemUser(SystemUsers systemUser){
SystemUsers lodedSystemUsers = (SystemUsers) session.load( SystemUsers.class, systemUser.getStringId() );
lodedSystemUsers.setName(systemUser.getName());
lodedSystemUsers.setStatus(systemUser.getStatus());
lodedSystemUsers.setRoles(systemUser.getRoles());
session.flush();
.....commitTransaction();
}

But is it a corerct way? If I'm wrong plese correct me..

Thank you.
Thilina


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 6:31 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
http://www.hibernate.org/hib_docs/v3/re ... tion-class

See dynamic-update="true|false"
"Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed."

This might help you.

Best regards
Sven


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.