Java 类org.hibernate.ObjectDeletedException 实例源码

项目:lams    文件:SessionImpl.java   
@Override
public LockMode getCurrentLockMode(Object object) throws HibernateException {
    errorIfClosed();
    checkTransactionSynchStatus();
    if ( object == null ) {
        throw new NullPointerException( "null object passed to getCurrentLockMode()" );
    }
    if ( object instanceof HibernateProxy ) {
        object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this);
        if ( object == null ) {
            return LockMode.NONE;
        }
    }
    EntityEntry e = persistenceContext.getEntry(object);
    if ( e == null ) {
        throw new TransientObjectException( "Given object not associated with the session" );
    }
    if ( e.getStatus() != Status.MANAGED ) {
        throw new ObjectDeletedException(
                "The given object was deleted",
                e.getId(),
                e.getPersister().getEntityName()
            );
    }
    return e.getLockMode();
}
项目:lams    文件:SessionImpl.java   
@Override
public void forceFlush(EntityEntry entityEntry) throws HibernateException {
    errorIfClosed();
    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Flushing to force deletion of re-saved object: %s",
                MessageHelper.infoString( entityEntry.getPersister(), entityEntry.getId(), getFactory() ) );
    }

    if ( persistenceContext.getCascadeLevel() > 0 ) {
        throw new ObjectDeletedException(
            "deleted object would be re-saved by cascade (remove deleted object from associations)",
            entityEntry.getId(),
            entityEntry.getPersister().getEntityName()
        );
    }

    flush();
}
项目:lams    文件:DefaultUpdateEventListener.java   
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
    // this implementation is supposed to tolerate incorrect unsaved-value
    // mappings, for the purpose of backward-compatibility
    EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
    if ( entry!=null ) {
        if ( entry.getStatus()== Status.DELETED ) {
            throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() );
        }
        else {
            return entityIsPersistent(event);
        }
    }
    else {
        entityIsDetached(event);
        return null;
    }
}
项目:cacheonix-core    文件:DefaultUpdateEventListener.java   
protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) {
    // this implementation is supposed to tolerate incorrect unsaved-value
    // mappings, for the purpose of backward-compatibility
    EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
    if ( entry!=null ) {
        if ( entry.getStatus()==Status.DELETED ) {
            throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() );
        }
        else {
            return entityIsPersistent(event);
        }
    }
    else {
        entityIsDetached(event);
        return null;
    }
}
项目:cacheonix-core    文件:SessionImpl.java   
public LockMode getCurrentLockMode(Object object) throws HibernateException {
    errorIfClosed();
    checkTransactionSynchStatus();
    if ( object == null ) {
        throw new NullPointerException( "null object passed to getCurrentLockMode()" );
    }
    if ( object instanceof HibernateProxy ) {
        object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this);
        if ( object == null ) {
            return LockMode.NONE;
        }
    }
    EntityEntry e = persistenceContext.getEntry(object);
    if ( e == null ) {
        throw new TransientObjectException( "Given object not associated with the session" );
    }
    if ( e.getStatus() != Status.MANAGED ) {
        throw new ObjectDeletedException( 
                "The given object was deleted", 
                e.getId(), 
                e.getPersister().getEntityName() 
            );
    }
    return e.getLockMode();
}
项目:cacheonix-core    文件:SessionImpl.java   
public void forceFlush(EntityEntry entityEntry) throws HibernateException {
    errorIfClosed();
    if ( log.isDebugEnabled() ) {
        log.debug(
            "flushing to force deletion of re-saved object: " +
            MessageHelper.infoString( entityEntry.getPersister(), entityEntry.getId(), getFactory() )
        );
    }

    if ( persistenceContext.getCascadeLevel() > 0 ) {
        throw new ObjectDeletedException(
            "deleted object would be re-saved by cascade (remove deleted object from associations)",
            entityEntry.getId(),
            entityEntry.getPersister().getEntityName()
        );
    }

    flush();
}
项目:cosmo    文件:ItemDaoImpl.java   
public void removeItem(Item item) {
    try {

        if (item == null) {
            throw new IllegalArgumentException("item cannot be null");
        }

        if (item instanceof HomeCollectionItem) {
            throw new IllegalArgumentException("cannot remove root item");
        }

        removeItemInternal(item);
        getSession().flush();

    } catch (ObjectNotFoundException onfe) {
        throw new ItemNotFoundException("item not found");
    } catch (ObjectDeletedException ode) {
        throw new ItemNotFoundException("item not found");
    } catch (UnresolvableObjectException uoe) {
        throw new ItemNotFoundException("item not found");
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}
项目:lams    文件:AbstractLockUpgradeEventListener.java   
/**
 * Performs a pessimistic lock upgrade on a given entity, if needed.
 *
 * @param object The entity for which to upgrade the lock.
 * @param entry The entity's EntityEntry instance.
 * @param lockOptions contains the requested lock mode.
 * @param source The session which is the source of the event being processed.
 */
protected void upgradeLock(Object object, EntityEntry entry, LockOptions lockOptions, EventSource source) {

    LockMode requestedLockMode = lockOptions.getLockMode();
    if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
        // The user requested a "greater" (i.e. more restrictive) form of
        // pessimistic lock

        if ( entry.getStatus() != Status.MANAGED ) {
            throw new ObjectDeletedException(
                    "attempted to lock a deleted instance",
                    entry.getId(),
                    entry.getPersister().getEntityName()
            );
        }

        final EntityPersister persister = entry.getPersister();

        if ( log.isTraceEnabled() ) {
            log.tracev(
                    "Locking {0} in mode: {1}",
                    MessageHelper.infoString( persister, entry.getId(), source.getFactory() ),
                    requestedLockMode
            );
        }

        final SoftLock lock;
        final CacheKey ck;
        if ( persister.hasCache() ) {
            ck = source.generateCacheKey( entry.getId(), persister.getIdentifierType(), persister.getRootEntityName() );
            lock = persister.getCacheAccessStrategy().lockItem( ck, entry.getVersion() );
        }
        else {
            ck = null;
            lock = null;
        }

        try {
            if ( persister.isVersioned() && requestedLockMode == LockMode.FORCE  ) {
                // todo : should we check the current isolation mode explicitly?
                Object nextVersion = persister.forceVersionIncrement(
                        entry.getId(), entry.getVersion(), source
                );
                entry.forceLocked( object, nextVersion );
            }
            else {
                persister.lock( entry.getId(), entry.getVersion(), object, lockOptions, source );
            }
            entry.setLockMode(requestedLockMode);
        }
        finally {
            // the database now holds a lock + the object is flushed from the cache,
            // so release the soft lock
            if ( persister.hasCache() ) {
                persister.getCacheAccessStrategy().unlockItem( ck, lock );
            }
        }

    }
}
项目:cacheonix-core    文件:DefaultPersistEventListener.java   
/** 
 * Handle the given create event.
 *
 * @param event The create event to be handled.
 * @throws HibernateException
 */
public void onPersist(PersistEvent event, Map createCache) throws HibernateException {

    final SessionImplementor source = event.getSession();
    final Object object = event.getObject();

    final Object entity;
    if (object instanceof HibernateProxy) {
        LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
        if ( li.isUninitialized() ) {
            if ( li.getSession()==source ) {
                return; //NOTE EARLY EXIT!
            }
            else {
                throw new PersistentObjectException("uninitialized proxy passed to persist()");
            }
        }
        entity = li.getImplementation();
    }
    else {
        entity = object;
    }

    int entityState = getEntityState( 
            entity, 
            event.getEntityName(), 
            source.getPersistenceContext().getEntry(entity), 
            source 
        );

    switch (entityState) {
        case DETACHED: 
            throw new PersistentObjectException( 
                    "detached entity passed to persist: " + 
                    getLoggableName( event.getEntityName(), entity ) 
                );
        case PERSISTENT:
            entityIsPersistent(event, createCache);
            break;
        case TRANSIENT:
            entityIsTransient(event, createCache);
            break;
        default: 
            throw new ObjectDeletedException( 
                    "deleted entity passed to persist", 
                    null, 
                    getLoggableName( event.getEntityName(), entity )
                );
    }

}