Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.EntityEntry


    final CollectionPersister cp = session.getFactory().getCollectionPersister( entity + '.' + property );

      // try cache lookup first
    final Object parent = parentsByChild.get( childEntity );
    if ( parent != null ) {
      final EntityEntry entityEntry = entityEntryContext.getEntityEntry( parent );
      //there maybe more than one parent, filter by type
      if ( persister.isSubclassEntityName( entityEntry.getEntityName() ) ) {
        Object index = getIndexInParent( property, childEntity, persister, cp, parent );

        if (index==null && mergeMap!=null) {
          final Object unMergedInstance = mergeMap.get( parent );
          final Object unMergedChild = mergeMap.get( childEntity );
          if ( unMergedInstance != null && unMergedChild != null ) {
            index = getIndexInParent( property, unMergedChild, persister, cp, unMergedInstance );
          }
        }
        if ( index != null ) {
          return index;
        }
      }
      else {
        // remove wrong entry
        parentsByChild.remove( childEntity );
      }
    }

    //Not found in cache, proceed
    for ( Entry<Object, EntityEntry> me : reentrantSafeEntityEntries() ) {
      final EntityEntry ee = me.getValue();
      if ( persister.isSubclassEntityName( ee.getEntityName() ) ) {
        final Object instance = me.getKey();

        Object index = getIndexInParent( property, childEntity, persister, cp, instance );
        if ( index==null && mergeMap!=null ) {
          final Object unMergedInstance = mergeMap.get( instance );
View Full Code Here


    boolean isReadOnly;
    if ( entityOrProxy instanceof HibernateProxy ) {
      isReadOnly = ( (HibernateProxy) entityOrProxy ).getHibernateLazyInitializer().isReadOnly();
    }
    else {
      final EntityEntry ee =  getEntry( entityOrProxy );
      if ( ee == null ) {
        throw new TransientObjectException("Instance was not associated with this persistence context" );
      }
      isReadOnly = ee.isReadOnly();
    }
    return isReadOnly;
  }
View Full Code Here

    }
    proxy.getHibernateLazyInitializer().setReadOnly( readOnly );
  }

  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;
  }
View Full Code Here

  }

  @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(),
        oldEntry.isLoadedWithLazyPropertiesUnfetched()
    );
  }
View Full Code Here

      final boolean debugEnabled = LOG.isDebugEnabled();
      for ( Serializable pk : getPersistenceContext().getNaturalIdHelper().getCachedPkResolutions( entityPersister ) ) {
        final EntityKey entityKey = generateEntityKey( pk, entityPersister );
        final Object entity = getPersistenceContext().getEntity( entityKey );
        final EntityEntry entry = getPersistenceContext().getEntry( entity );

        if ( entry == null ) {
          if ( debugEnabled ) {
            LOG.debug(
                "Cached natural-id/pk resolution linked to null EntityEntry in persistence context : "
                    + MessageHelper.infoString( entityPersister, pk, getFactory() )
            );
          }
          continue;
        }

        if ( !entry.requiresDirtyCheck( entity ) ) {
          continue;
        }

        // MANAGED is the only status we care about here...
        if ( entry.getStatus() != Status.MANAGED ) {
          continue;
        }

        getPersistenceContext().getNaturalIdHelper().handleSynchronization(
            entityPersister,
View Full Code Here

      // We have a physical or logical one-to-one.  See if the attribute cascade settings and action-type require
      // orphan checking
      if ( style.hasOrphanDelete() && action.deleteOrphans() ) {
        // value is orphaned if loaded state for this property shows not null
        // because it is currently null.
        final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent );
        if ( entry != null && entry.getStatus() != Status.SAVING ) {
          final Object loadedValue;
          if ( componentPathStack.isEmpty() ) {
            // association defined on entity
            loadedValue = entry.getLoadedValue( propertyName );
          }
          else {
            // association defined on component
            //     todo : this is currently unsupported because of the fact that
            //    we do not know the loaded state of this value properly
            //    and doing so would be very difficult given how components and
            //    entities are loaded (and how 'loaded state' is put into the
            //    EntityEntry).  Solutions here are to either:
            //      1) properly account for components as a 2-phase load construct
            //      2) just assume the association was just now orphaned and
            //         issue the orphan delete.  This would require a special
            //        set of SQL statements though since we do not know the
            //        orphaned value, something a delete with a subquery to
            //         match the owner.
//              final EntityType entityType = (EntityType) type;
//              final String getPropertyPath = composePropertyPath( entityType.getPropertyName() );
            loadedValue = null;
          }
         
          // orphaned if the association was nulled (child == null) or receives a new value while the
          // entity is managed (without first nulling and manually flushing).
          if ( child == null || ( loadedValue != null && child != loadedValue ) ) {
            final EntityEntry valueEntry = eventSource
                .getPersistenceContext().getEntry(
                    loadedValue );
            // Need to check this in case the context has
            // already been flushed.  See HHH-7829.
            if ( valueEntry != null ) {
              final String entityName = valueEntry.getPersister().getEntityName();
              if ( LOG.isTraceEnabled() ) {
                final Serializable id = valueEntry.getPersister().getIdentifier( loadedValue, eventSource );
                final String description = MessageHelper.infoString( entityName, id );
                LOG.tracev( "Deleting orphaned entity instance: {0}", description );
              }
             
              if (type.isAssociationType() && ((AssociationType)type).getForeignKeyDirection().equals(
View Full Code Here

      // See if the entity is already bound to this session, if not look at the
      // entity identifier and assume that the entity is persistent if the
      // id is not "unsaved" (that is, we rely on foreign keys to keep
      // database integrity)

      final EntityEntry entityEntry = session.getPersistenceContext().getEntry( object );
      if ( entityEntry == null ) {
        return isTransient( entityName, object, null, session );
      }
      else {
        return entityEntry.isNullifiable( isEarlyInsert, session );
      }

    }
View Full Code Here

      final Object entity,
      final boolean readOnly,
      final SessionImplementor session,
      final PreLoadEvent preLoadEvent) {
    final PersistenceContext persistenceContext = session.getPersistenceContext();
    final EntityEntry entityEntry = persistenceContext.getEntry( entity );
    if ( entityEntry == null ) {
      throw new AssertionFailure( "possible non-threadsafe access to the session" );
    }
    doInitializeEntity( entity, entityEntry, readOnly, session, preLoadEvent );
  }
View Full Code Here

      final PostLoadEvent postLoadEvent) {
   
    if ( session.isEventSource() ) {
      final PersistenceContext persistenceContext
          = session.getPersistenceContext();
      final EntityEntry entityEntry = persistenceContext.getEntry( entity );

      postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );

      final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
              .getServiceRegistry()
              .getService( EventListenerRegistry.class )
              .getEventListenerGroup( EventType.POST_LOAD );
View Full Code Here

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