There are certain situations where we need to use "Where" clause while update. Mainly on concurrency handling situation.
In hibernate usual procedure is :
sess.load (object);
-- Update all the values in the object
then call object.save() or object.update()
then call sess.flush()
--> By the above scenario objects are saved to the database and flush will make sure that objects is flushed with current updated value in the memory.
This can take care of the concurrency inside the appplication (I.e if all the update happen through the hibernate within same application). But our situation is bit different, it is possible that database might be updated externally.
The updated values can not be reflected to the hibernate objects. So if some one does the update externally, and application may not aware of that, then it will also update the value in the database.
To avoid that we have a flag in database which will be automatically updated, whenever update happens by any means.
During the update call from application --> "Where" clause will be used to make sure the flag is same as while read.
Expected solution:
Hibernate says somethign about load --> Which locks the particular row in the database (SaveorUpdate()...).
I couldn't undestand this properly. If you can get the answer from the concerned person on how to handle:
Either
1. "Where" Clause while update
or
2. Lock the record before update (Which fetches the current value in the database as well).
|