Package org.hibernate

Examples of org.hibernate.PersistentObjectException


      id = persister.getIdentifier( object, event.getSession() );
            if (LOG.isTraceEnabled()) LOG.trace("Refreshing transient "
                                                + MessageHelper.infoString(persister, id, source.getFactory()));
      final EntityKey key = source.generateEntityKey( id, persister );
      if ( source.getPersistenceContext().getEntry(key) != null ) {
        throw new PersistentObjectException(
            "attempted to refresh transient instance when persistent instance was already associated with the Session: " +
            MessageHelper.infoString(persister, id, source.getFactory() )
          );
      }
    }
View Full Code Here


      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;
    }

    final String entityName;
    if ( event.getEntityName() != null ) {
      entityName = event.getEntityName();
    }
    else {
      entityName = source.bestGuessEntityName( entity );
      event.setEntityName( entityName );
    }

    final EntityEntry entityEntry = source.getPersistenceContext().getEntry( entity );
    int entityState = getEntityState( entity, entityName, entityEntry, source );
    if ( entityState == DETACHED ) {
      // JPA 2, in its version of a "foreign generated", allows the id attribute value
      // to be manually set by the user, even though this manual value is irrelevant.
      // The issue is that this causes problems with the Hibernate unsaved-value strategy
      // which comes into play here in determining detached/transient state.
      //
      // Detect if we have this situation and if so null out the id value and calculate the
      // entity state again.

      // NOTE: entityEntry must be null to get here, so we cannot use any of its values
      EntityPersister persister = source.getFactory().getEntityPersister( entityName );
      if ( ForeignGenerator.class.isInstance( persister.getIdentifierGenerator() ) ) {
                if (LOG.isDebugEnabled() && persister.getIdentifier(entity, source) != null) LOG.debugf("Resetting entity id attribute to null for foreign generator");
        persister.setIdentifier( entity, null, source );
        entityState = getEntityState( entity, entityName, entityEntry, source );
      }
    }

    switch ( entityState ) {
      case DETACHED:
        throw new PersistentObjectException(
            "detached entity passed to persist: " +
                getLoggableName( event.getEntityName(), entity )
        );
      case PERSISTENT:
        entityIsPersistent( event, createCache );
View Full Code Here

        final boolean isEqual = !entityEntry.getPersister().getIdentifierType()
            .isEqual( requestedId, entityEntry.getId(), event.getSession().getEntityMode(), factory );

        if ( isEqual ) {
          throw new PersistentObjectException(
              "object passed to save() was already persistent: " +
                  MessageHelper.infoString( entityEntry.getPersister(), requestedId, factory )
          );
        }
View Full Code Here

    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        throw new PersistentObjectException(
            "object was an uninitialized proxy for " +
            li.getEntityName()
        );
      }
      return li.getImplementation(); //unwrap the object
View Full Code Here

    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        throw new PersistentObjectException(
            "object was an uninitialized proxy for " +
            li.getEntityName()
        );
      }
      return li.getImplementation(); //unwrap the object
View Full Code Here

    final EntityKey keyToLoad,
    final LoadEventListener.LoadType options) {

    if ( event.getInstanceToLoad() != null ) {
      if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
        throw new PersistentObjectException(
            "attempted to load into an instance that was already associated with the session: " +
            MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
          );
      }
      persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() );
View Full Code Here

    final EntityKey keyToLoad,
    final LoadEventListener.LoadType options) {

    if ( event.getInstanceToLoad() != null ) {
      if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
        throw new PersistentObjectException(
            "attempted to load into an instance that was already associated with the session: " +
            MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
          );
      }
      persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() );
View Full Code Here

            MessageHelper.infoString( persister, id, source.getFactory() )
          );
      }
      EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
      if ( source.getPersistenceContext().getEntry(key) != null ) {
        throw new PersistentObjectException(
            "attempted to refresh transient instance when persistent instance was already associated with the Session: " +
            MessageHelper.infoString(persister, id, source.getFactory() )
          );
      }
    }
View Full Code Here

   
    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        throw new PersistentObjectException(
            "object was an uninitialized proxy for " +
            li.getEntityName()
        );
      }
      return li.getImplementation(); //unwrap the object
View Full Code Here

    final EntityKey keyToLoad,
    final LoadEventListener.LoadType options) {

    if ( event.getInstanceToLoad() != null ) {
      if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
        throw new PersistentObjectException(
            "attempted to load into an instance that was already associated with the session: " +
            MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
          );
      }
      persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession().getEntityMode() );
View Full Code Here

TOP

Related Classes of org.hibernate.PersistentObjectException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.