Search in sources :

Example 6 with EntityEntry

use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.

the class PessimisticForceIncrementLockingStrategy method lock.

@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
    if (!lockable.isVersioned()) {
        throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
    }
    final EntityEntry entry = session.getPersistenceContext().getEntry(object);
    final EntityPersister persister = entry.getPersister();
    final Object nextVersion = persister.forceVersionIncrement(entry.getId(), entry.getVersion(), session);
    entry.forceLocked(object, nextVersion);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) EntityEntry(org.hibernate.engine.spi.EntityEntry) HibernateException(org.hibernate.HibernateException)

Example 7 with EntityEntry

use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.

the class OptimisticForceIncrementLockingStrategy method lock.

@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
    if (!lockable.isVersioned()) {
        throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
    }
    final EntityEntry entry = session.getPersistenceContext().getEntry(object);
    // Register the EntityIncrementVersionProcess action to run just prior to transaction commit.
    ((EventSource) session).getActionQueue().registerProcess(new EntityIncrementVersionProcess(object, entry));
}
Also used : EntityEntry(org.hibernate.engine.spi.EntityEntry) HibernateException(org.hibernate.HibernateException) EntityIncrementVersionProcess(org.hibernate.action.internal.EntityIncrementVersionProcess)

Example 8 with EntityEntry

use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.

the class EntityEntryContext method removeEntityEntry.

/**
	 * Remove an entity from the context, returning the EntityEntry which was associated with it
	 *
	 * @param entity The entity to remove
	 *
	 * @return Tjee EntityEntry
	 */
public EntityEntry removeEntityEntry(Object entity) {
    // locate a ManagedEntity for the entity, but only if it is associated with the same PersistenceContext.
    // no need to check if the entity is a ManagedEntity that is associated with a different PersistenceContext
    final ManagedEntity managedEntity = getAssociatedManagedEntity(entity);
    if (managedEntity == null) {
        // not associated with this EntityEntryContext, so nothing to do.
        return null;
    }
    dirty = true;
    if (ImmutableManagedEntityHolder.class.isInstance(managedEntity)) {
        assert entity == ((ImmutableManagedEntityHolder) managedEntity).managedEntity;
        immutableManagedEntityXref.remove((ManagedEntity) entity);
    } else if (!ManagedEntity.class.isInstance(entity)) {
        nonEnhancedEntityXref.remove(entity);
    }
    // prepare for re-linking...
    final ManagedEntity previous = managedEntity.$$_hibernate_getPreviousManagedEntity();
    final ManagedEntity next = managedEntity.$$_hibernate_getNextManagedEntity();
    managedEntity.$$_hibernate_setPreviousManagedEntity(null);
    managedEntity.$$_hibernate_setNextManagedEntity(null);
    // re-link
    count--;
    if (count == 0) {
        // handle as a special case...
        head = null;
        tail = null;
        assert previous == null;
        assert next == null;
    } else {
        // otherwise, previous or next (or both) should be non-null
        if (previous == null) {
            // we are removing head
            assert managedEntity == head;
            head = next;
        } else {
            previous.$$_hibernate_setNextManagedEntity(next);
        }
        if (next == null) {
            // we are removing tail
            assert managedEntity == tail;
            tail = previous;
        } else {
            next.$$_hibernate_setPreviousManagedEntity(previous);
        }
    }
    // finally clean out the ManagedEntity and return the associated EntityEntry
    final EntityEntry theEntityEntry = managedEntity.$$_hibernate_getEntityEntry();
    managedEntity.$$_hibernate_setEntityEntry(null);
    return theEntityEntry;
}
Also used : ManagedEntity(org.hibernate.engine.spi.ManagedEntity) EntityEntry(org.hibernate.engine.spi.EntityEntry)

Example 9 with EntityEntry

use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.

the class StatefulPersistenceContext method setEntityReadOnly.

private void setEntityReadOnly(Object entity, boolean readOnly) {
    final EntityEntry entry = getEntry(entity);
    if (entry == null) {
        throw new TransientObjectException("Instance was not associated with this persistence context");
    }
    entry.setReadOnly(readOnly, entity);
    hasNonReadOnlyEntities = hasNonReadOnlyEntities || !readOnly;
}
Also used : TransientObjectException(org.hibernate.TransientObjectException) EntityEntry(org.hibernate.engine.spi.EntityEntry)

Example 10 with EntityEntry

use of org.hibernate.engine.spi.EntityEntry in project hibernate-orm by hibernate.

the class StatefulPersistenceContext method replaceDelayedEntityIdentityInsertKeys.

@Override
public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId) {
    final Object entity = entitiesByKey.remove(oldKey);
    final EntityEntry oldEntry = entityEntryContext.removeEntityEntry(entity);
    parentsByChild.clear();
    final EntityKey newKey = session.generateEntityKey(generatedId, oldEntry.getPersister());
    addEntity(newKey, entity);
    addEntry(entity, oldEntry.getStatus(), oldEntry.getLoadedState(), oldEntry.getRowId(), generatedId, oldEntry.getVersion(), oldEntry.getLockMode(), oldEntry.isExistsInDatabase(), oldEntry.getPersister(), oldEntry.isBeingReplicated());
}
Also used : EntityKey(org.hibernate.engine.spi.EntityKey) EntityEntry(org.hibernate.engine.spi.EntityEntry)

Aggregations

EntityEntry (org.hibernate.engine.spi.EntityEntry)79 Serializable (java.io.Serializable)22 EntityPersister (org.hibernate.persister.entity.EntityPersister)21 Session (org.hibernate.Session)18 Test (org.junit.Test)17 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)16 AbstractPersistentCollection (org.hibernate.collection.internal.AbstractPersistentCollection)12 EntityKey (org.hibernate.engine.spi.EntityKey)12 TestForIssue (org.hibernate.testing.TestForIssue)12 AssertionFailure (org.hibernate.AssertionFailure)11 HibernateProxy (org.hibernate.proxy.HibernateProxy)11 HibernateException (org.hibernate.HibernateException)10 EventSource (org.hibernate.event.spi.EventSource)9 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)8 TransientObjectException (org.hibernate.TransientObjectException)7 PersistentCollection (org.hibernate.collection.spi.PersistentCollection)7 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)6 Status (org.hibernate.engine.spi.Status)6 LazyInitializer (org.hibernate.proxy.LazyInitializer)6 EntityRegionAccessStrategy (org.hibernate.cache.spi.access.EntityRegionAccessStrategy)5