• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Updating a Object

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was expecting an answer related to optimistic lock attribute .
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic