Search in sources :

Example 1 with Lifecycle

use of org.hibernate.classic.Lifecycle 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());
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityEntry(org.hibernate.engine.spi.EntityEntry) AssertionFailure(org.hibernate.AssertionFailure) EntityVerifyVersionProcess(org.hibernate.action.internal.EntityVerifyVersionProcess) Lifecycle(org.hibernate.classic.Lifecycle) LockMode(org.hibernate.LockMode) EntityIncrementVersionProcess(org.hibernate.action.internal.EntityIncrementVersionProcess)

Aggregations

AssertionFailure (org.hibernate.AssertionFailure)1 LockMode (org.hibernate.LockMode)1 EntityIncrementVersionProcess (org.hibernate.action.internal.EntityIncrementVersionProcess)1 EntityVerifyVersionProcess (org.hibernate.action.internal.EntityVerifyVersionProcess)1 Lifecycle (org.hibernate.classic.Lifecycle)1 EntityEntry (org.hibernate.engine.spi.EntityEntry)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1