aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Updating a Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Updating a Object" Watch "Hibernate Updating a Object" New topic
Author

Hibernate Updating a Object

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


Hi ,

When going through the Hibernate Tutorials , i read that

When there is no change to the Object Hibernate doesn’t perform update explicitly.
Can anybody please let me how to achieve this behaviour in Hibernate ?


Thanks in advance .


Save India From Corruption - Anna Hazare.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

If that's the default behavior, it's achieved automatically, is it not?

So, if this is the Hibernate default, and you want the Hibernate default, I would imagine the best way to achieve this is to program with Hiberante.

-Cameron McKenzie
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I was expecting an answer related to optimistic lock attribute .
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Ravi Kiran Varre wrote:I was expecting an answer related to optimistic lock attribute .


Sure! What do you want to know about optimistic locking?

Could you rephrase the questions in terms of Hibernate and optimistic/pessimistic locking? That might help us get to the answer you need.

Kindest regards,

-Cameron McKenzie
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Okay fine .

I am in a confusion that if one uses the Optimistic-lock attribute =true in a hbm file . Then this feature (Updating the Object only its values are chnaged) will come into picture otherwise not .

Please guide me .

Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 189
Optimistic locking and updating only objects that are changed are two different things.

Updating objects:
As long as an object is "connected" to the hibernate session changes are automatically detected and hibernate writes these changes back to database when the transaction is commited.

Optimistic locking:
If you declare a column for versioning purposes hibernate increments this value each time it updates a database row. Say you have a column id which keeps your ID and version which keeps the version. Using optimistic locking does an update like this "..., version = ? where id = ? and version = ?". Because hibernate read the database row with a certain ID and Version an update to that row has to update exactly one row. So if the update statement returns 0, hibernate knows that the row is deleted or updated by another transaction.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you , Now i understood that its the default behaviour of Hibernate , and nothing to do with the attribute optimistic locking.
 
Consider Paul's rocket mass heater.
 
subject: Hibernate Updating a Object