use of org.hibernate.action.internal.EntityVerifyVersionProcess in project hibernate-orm by hibernate.
the class DefaultPostLoadEventListener method onPostLoad.
@Override
public void onPostLoad(PostLoadEvent event) {
final Object entity = event.getEntity();
callbackRegistry.postLoad(entity);
final EntityEntry entry = event.getSession().getPersistenceContext().getEntry(entity);
if (entry == null) {
throw new AssertionFailure("possible non-threadsafe access to the session");
}
final LockMode lockMode = entry.getLockMode();
if (LockMode.PESSIMISTIC_FORCE_INCREMENT.equals(lockMode)) {
final EntityPersister persister = entry.getPersister();
final Object nextVersion = persister.forceVersionIncrement(entry.getId(), entry.getVersion(), event.getSession());
entry.forceLocked(entity, nextVersion);
} else if (LockMode.OPTIMISTIC_FORCE_INCREMENT.equals(lockMode)) {
final EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess(entity, entry);
event.getSession().getActionQueue().registerProcess(incrementVersion);
} else if (LockMode.OPTIMISTIC.equals(lockMode)) {
final EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess(entity, entry);
event.getSession().getActionQueue().registerProcess(verifyVersion);
}
if (event.getPersister().implementsLifecycle()) {
// log.debug( "calling onLoad()" );
((Lifecycle) event.getEntity()).onLoad(event.getSession(), event.getId());
}
}
use of org.hibernate.action.internal.EntityVerifyVersionProcess 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