Hi everyone,
I am fairly new to Hibernate and I have a (hopefully) simple question.
I am using the following code to check if a lock on a dataset has changed.
First I load the current lock.. then I save the object and then I check if the lock has been altered in the database using optimistic locking.
Code:
public void saveObject(T object, LOCK lock){
Session session = getSession();
// check if we still have the lock on the row
LOCK currentLock = (LOCK) session.get(lockClass, lock.getId());
// do some stuff
// and rewrite the lock
session.update(currentLock);
}
The LOCK object is annotated like this
Code:
@Entity
@org.hibernate.annotations.Entity(optimisticLock = OptimisticLockType.ALL, dynamicUpdate = true)
My problem now is that hibernate only checks the lock for changes in the database (by performing an update) if the LOCK object has changed in the session (which I suppose is because of dynamic-update=true). If nothing changed the update is never executed. If I remove the dynamicUpdate attribute hibernate throws an exception because OptimisticLockType.ALL requires dynamic updates.
So is there a way to force hibernate to execute the update or is this the wrong approach?
Best Regards
Carsten