use of org.hibernate.OptimisticLockException in project hibernate-orm by hibernate.
the class EntityVerifyVersionProcess method doBeforeTransactionCompletion.
@Override
public void doBeforeTransactionCompletion(SessionImplementor session) {
final EntityPersister persister = entry.getPersister();
if (!entry.isExistsInDatabase()) {
// HHH-9419: We cannot check for a version of an entry we ourselves deleted
return;
}
final Object latestVersion = persister.getCurrentVersion(entry.getId(), session);
if (!entry.getVersion().equals(latestVersion)) {
throw new OptimisticLockException(object, "Newer version [" + latestVersion + "] of entity [" + MessageHelper.infoString(entry.getEntityName(), entry.getId()) + "] found in database");
}
}
use of org.hibernate.OptimisticLockException in project hibernate-orm by hibernate.
the class OptimisticLockingStrategy method lock.
@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
if (!lockable.isVersioned()) {
throw new OptimisticLockException(object, "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
}
final EntityEntry entry = session.getPersistenceContext().getEntry(object);
// Register the EntityVerifyVersionProcess action to run just prior to transaction commit.
((EventSource) session).getActionQueue().registerProcess(new EntityVerifyVersionProcess(object, entry));
}
Aggregations