aspose file tools*
The moose likes Object Relational Mapping and the fly likes Updating single column using Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Updating single column using Hibernate" Watch "Updating single column using Hibernate" New topic
Author

Updating single column using Hibernate

Raghusham Sankargal
Ranch Hand

Joined: Oct 10, 2005
Posts: 59
Hi I have login table with user and password. The password can be changed more than once.
In this way I want to update only that column.
Would you please how to do that ?

Thanksin advance,
Sham


Raghusham Sankargal
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

As long as the object is loaded,created,saved or queried by the session all the changes in the state will be persisted (i.e: automatic dirty checking by Hibernate) by the Hibernate when the session is flushed.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Raghusham Sankargal
Ranch Hand

Joined: Oct 10, 2005
Posts: 59
Hi,
Thanks for the reply.
Do you mean that the Hibernate makes sure it updates only those columns that are updated by the checking the row present in the database, takes the one that are new and then updates only them?

Kind Regards, Sham.
javascript:emoticon('');
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 129
There is an element called "dynamic-update" that should be defined in your class definition in hibernate hbm files. By default its value will be false, it means that hibernate will generate update statement for all columns. If its value is true, then hibernate will generate update statement on run time and include only those colums whose values has been changed.

You can use dynamic-update=true. Below is the syntax for using this.

<class
name="ClassName" table="table" dynamic-update="true "

-Sunil
Vishwas Tyagi
Greenhorn

Joined: May 08, 2011
Posts: 4


In case of detached state, update(Object o) updates all columns of that table row.
If, i want to update only one column,then how to do that?

Suppose, i fire get method and hibernate returns me object say of Employee class, then i fire evict() on session.
now i update employee name, and calls update method .
In this case update method updates, all columns of the table(we can see query generated by hibernate using show_sql property).
i want to update only employee name and not rest of the columns , then how to do that?
Please Help
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Updating single column using Hibernate
 
Similar Threads
Problem in SQL (MySQL) select password column
realm,acls in weblogic
creating login table for webapplication
creating an encrypted column
Store char[] as column type