Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Updating a Object

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 .
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was expecting an answer related to optimistic lock attribute .
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you , Now i understood that its the default behaviour of Hibernate , and nothing to do with the attribute optimistic locking.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic