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 ?
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 .
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.