Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.EntityEntry


    if ( refreshedAlready.containsKey(object) ) {
      LOG.trace( "Already refreshed" );
      return;
    }

    final EntityEntry e = source.getPersistenceContext().getEntry( object );
    final EntityPersister persister;
    final Serializable id;

    if ( e == null ) {
      persister = source.getEntityPersister(event.getEntityName(), object); //refresh() does not pass an entityName
      id = persister.getIdentifier( object, event.getSession() );
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "Refreshing transient {0}", 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() )
          );
      }
    }
    else {
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "Refreshing ", MessageHelper.infoString( e.getPersister(), e.getId(), source.getFactory() ) );
      }
      if ( !e.isExistsInDatabase() ) {
        throw new HibernateException( "this instance does not yet exist as a row in the database" );
      }

      persister = e.getPersister();
      id = e.getId();
    }

    // cascade the refresh prior to refreshing this entity
    refreshedAlready.put(object, object);
    new Cascade( CascadingAction.REFRESH, Cascade.BEFORE_REFRESH, source)
        .cascade( persister, object, refreshedAlready );

    if ( e != null ) {
      final EntityKey key = source.generateEntityKey( id, persister );
      source.getPersistenceContext().removeEntity(key);
      if ( persister.hasCollections() ) new EvictVisitor( source ).process(object, persister);
    }

    if ( persister.hasCache() ) {
      final CacheKey ck = source.generateCacheKey(
          id,
          persister.getIdentifierType(),
          persister.getRootEntityName()
      );
      persister.getCacheAccessStrategy().evict( ck );
    }

    evictCachedCollections( persister, id, source.getFactory() );

    String previousFetchProfile = source.getLoadQueryInfluencers().getInternalFetchProfile();
    source.getLoadQueryInfluencers().setInternalFetchProfile( "refresh" );
    Object result = persister.load( id, object, event.getLockOptions(), source );
    // Keep the same read-only/modifiable setting for the entity that it had before refreshing;
    // If it was transient, then set it to the default for the source.
    if ( result != null ) {
      if ( ! persister.isMutable() ) {
        // this is probably redundant; it should already be read-only
        source.setReadOnly( result, true );
      }
      else {
        source.setReadOnly( result, ( e == null ? source.isDefaultReadOnly() : e.isReadOnly() ) );
      }
    }
    source.getLoadQueryInfluencers().setInternalFetchProfile(previousFetchProfile);

    UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
View Full Code Here


          final Object subId;
          if ( HibernateProxy.class.isInstance( propertyValues[i] ) ) {
            subId = ( (HibernateProxy) propertyValues[i] ).getHibernateLazyInitializer().getIdentifier();
          }
          else {
            EntityEntry pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] );
            if ( pcEntry != null ) {
              subId = pcEntry.getId();
            }
            else {
              LOG.debug( "Performing implicit derived identity cascade" );
              final PersistEvent event = new PersistEvent( null, propertyValues[i], (EventSource) session );
              for ( PersistEventListener listener : persistEventListeners( session ) ) {
                listener.onPersist( event );
              }
              pcEntry = session.getPersistenceContext().getEntry( propertyValues[i] );
              if ( pcEntry == null || pcEntry.getId() == null ) {
                throw new HibernateException( "Unable to process implicit derived identity cascade" );
              }
              else {
                subId = pcEntry.getId();
              }
            }
          }
          propertyValues[i] = subId;
        }
View Full Code Here

      Object entity = mapEntry.getKey();
      Object copy = mapEntry.getValue();
      if ( copy instanceof HibernateProxy ) {
        copy = ( (HibernateProxy) copy ).getHibernateLazyInitializer().getImplementation();
      }
      EntityEntry copyEntry = event.getSession().getPersistenceContext().getEntry( copy );
      if ( copyEntry == null ) {
        // entity name will not be available for non-POJO entities
        if ( LOG.isTraceEnabled() ) {
          LOG.tracev( "Transient instance could not be processed by merge: {0} [{1}]",
              event.getSession().guessEntityName( copy ), entity );
        }
        // merge did not cascade to this entity; it's in copyCache because a
        // different entity has a non-nullable reference to this entity;
        // this entity should not be put in transientCopyCache, because it was
        // not included in the merge;
        // if the global setting for checking nullability is false, the non-nullable
        // reference to this entity will be detected later
        if ( isNullabilityCheckedGlobal( event.getSession() ) ) {
          throw new TransientObjectException(
            "object is an unsaved transient instance - save the transient instance before merging: " +
              event.getSession().guessEntityName( copy )
          );
        }
      }
      else if ( copyEntry.getStatus() == Status.SAVING ) {
        transientCopyCache.put( entity, copy, copyCache.isOperatedOn( entity ) );
      }
      else if ( copyEntry.getStatus() != Status.MANAGED && copyEntry.getStatus() != Status.READ_ONLY ) {
        throw new AssertionFailure( "Merged entity does not have status set to MANAGED or READ_ONLY; "+copy+" status="+copyEntry.getStatus() );
      }
    }
    return transientCopyCache;
  }
View Full Code Here

    // For now, just run through the transient entities and retry the merge
    for ( Iterator it=transientCopyCache.entrySet().iterator(); it.hasNext(); ) {
      Map.Entry mapEntry = ( Map.Entry ) it.next();
      Object entity = mapEntry.getKey();
      Object copy = transientCopyCache.get( entity );
      EntityEntry copyEntry = event.getSession().getPersistenceContext().getEntry( copy );
      mergeTransientEntity(
          entity,
          copyEntry.getEntityName(),
          ( entity == event.getEntity() ? event.getRequestedId() : copyEntry.getId() ),
          event.getSession(),
          copyCache,
          isNullabilityChecked
      );
    }
View Full Code Here

        event.setEntity( entity );
        EntityState entityState = null;

        // Check the persistence context for an entry relating to this
        // entity to be merged...
        EntityEntry entry = source.getPersistenceContext().getEntry( entity );
        if ( entry == null ) {
          EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
          Serializable id = persister.getIdentifier( entity, source );
          if ( id != null ) {
            final EntityKey key = source.generateEntityKey( id, persister );
View Full Code Here

    catch (PropertyValueException ex) {
      String propertyName = ex.getPropertyName();
      Object propertyFromCopy = persister.getPropertyValue( copy, propertyName );
      Object propertyFromEntity = persister.getPropertyValue( entity, propertyName );
      Type propertyType = persister.getPropertyType( propertyName );
      EntityEntry copyEntry = source.getPersistenceContext().getEntry( copy );
      if ( propertyFromCopy == null ||
          propertyFromEntity == null ||
          ! propertyType.isEntityType() ||
          ! copyCache.containsKey( propertyFromEntity ) ) {
        if ( LOG.isTraceEnabled() ) {
                    LOG.trace("Property '" + copyEntry.getEntityName() + "." + propertyName + "' in copy is "
                              + (propertyFromCopy == null ? "null" : propertyFromCopy));
                    LOG.trace("Property '" + copyEntry.getEntityName() + "." + propertyName + "' in original is "
                              + (propertyFromCopy == null ? "null" : propertyFromCopy));
                    LOG.trace("Property '" + copyEntry.getEntityName() + "." + propertyName + "' is"
                              + (propertyType.isEntityType() ? "" : " not") + " an entity type");
                    if (propertyFromEntity != null && !copyCache.containsKey(propertyFromEntity)) {
            LOG.tracef(
                "Property '%s.%s' is not in copy cache",
                copyEntry.getEntityName(),
                propertyName
            );
          }
              }
                if ( isNullabilityCheckedGlobal( source ) ) {
                    throw ex;
                }
                else {
                    // retry save w/o checking for non-nullable properties
                    // (the failure will be detected later)
                    saveTransientEntity( copy, entityName, requestedId, source, copyCache, false );
        }
      }
      if ( LOG.isTraceEnabled() && propertyFromEntity != null ) {
                if (((EventCache)copyCache).isOperatedOn(propertyFromEntity)) LOG.trace("Property '"
                                                                                        + copyEntry.getEntityName()
                                                                                        + "."
                                                                                        + propertyName
                                                                                        + "' from original entity is in copyCache and is in the process of being merged; "
                                                                                        + propertyName + " =[" + propertyFromEntity
                                                                                        + "]");
                else LOG.trace("Property '" + copyEntry.getEntityName() + "." + propertyName
                               + "' from original entity is in copyCache and is not in the process of being merged; "
                               + propertyName + " =[" + propertyFromEntity + "]");
      }
      // continue...; we'll find out if it ends up not getting saved later
    }
View Full Code Here

    errorIfClosed();
    if ( object instanceof HibernateProxy ) {
      return getProxyIdentifier( object );
    }
    else {
      EntityEntry entry = persistenceContext.getEntry(object);
      return entry != null ? entry.getId() : null;
    }
  }
View Full Code Here

      }
    }
    // A session is considered to contain an entity only if the entity has
    // an entry in the session's persistence context and the entry reports
    // that the entity has not been removed
    EntityEntry entry = persistenceContext.getEntry( object );
    return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
  }
View Full Code Here

      if ( initializer.isUninitialized() ) {
        return initializer.getEntityName();
      }
      object = initializer.getImplementation();
    }
    EntityEntry entry = persistenceContext.getEntry(object);
    if (entry==null) {
      return guessEntityName(object);
    }
    else {
      return entry.getPersister().getEntityName();
    }
  }
View Full Code Here

        throw new TransientObjectException("proxy was not associated with the session");
      }
      object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
    }

    EntityEntry entry = persistenceContext.getEntry(object);
    if ( entry == null ) {
      throwTransientObjectException( object );
    }
    return entry.getPersister().getEntityName();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.spi.EntityEntry

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.