jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Updating single column using Hibernate" Watch "Updating single column using Hibernate" New topic

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,

Raghusham Sankargal
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3902

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.

[How to ask questions] [Twitter]
Raghusham Sankargal
Ranch Hand

Joined: Oct 10, 2005
Posts: 59
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.
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 137
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.

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

Vishwas Tyagi

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Updating single column using Hibernate
It's not a secret anymore!