Package org.hibernate.engine

Examples of org.hibernate.engine.EntityEntry


  private Serializable getId(Object entity, AbstractCollectionEvent event) {
    Serializable id = event.getAffectedOwnerIdOrNull();
    if ( id == null ) {
      //most likely this recovery is unnecessary since Hibernate Core probably try that
      EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry( entity );
      id = entityEntry == null ? null : entityEntry.getId();
    }
    return id;
  }
View Full Code Here


  private Serializable getId(Object entity, AbstractCollectionEvent event) {
    Serializable id = event.getAffectedOwnerIdOrNull();
    if ( id == null ) {
      //most likely this recovery is unnecessary since Hibernate Core probably try that
      EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry( entity );
      id = entityEntry == null ? null : entityEntry.getId();
    }
    return id;
  }
View Full Code Here

          rowId,
          session
      );
    }

    EntityEntry entry = getSession().getPersistenceContext().getEntry( instance );
    if ( entry == null ) {
      throw new AssertionFailure( "possible nonthreadsafe access to session" );
    }
   
    if ( entry.getStatus()==Status.MANAGED || persister.isVersionPropertyGenerated() ) {
      // get the updated snapshot of the entity state by cloning current state;
      // it is safe to copy in place, since by this time no-one else (should have)
      // has a reference  to the array
      TypeFactory.deepCopy(
          state,
          persister.getPropertyTypes(),
          persister.getPropertyCheckability(),
          state,
          session
      );
      if ( persister.hasUpdateGeneratedProperties() ) {
        // this entity defines proeprty generation, so process those generated
        // values...
        persister.processUpdateGeneratedProperties( id, instance, state, session );
        if ( persister.isVersionPropertyGenerated() ) {
          nextVersion = Versioning.getVersion( state, persister );
        }
      }
      // have the entity entry perform post-update processing, passing it the
      // update state and the new version (if one).
      entry.postUpdate( instance, state, nextVersion );
    }

    if ( persister.hasCache() ) {
      if ( persister.isCacheInvalidationRequired() || entry.getStatus()!=Status.MANAGED ) {
        persister.getCacheAccessStrategy().remove( ck );
      }
      else {
        //TODO: inefficient if that cache is just going to ignore the updated state!
        CacheEntry ce = new CacheEntry(
View Full Code Here

    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(null, object); //refresh() does not pass an entityName
      id = persister.getIdentifier( object, event.getSession().getEntityMode() );
      if ( log.isTraceEnabled() ) {
        log.trace(
            "refreshing transient " +
            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() )
          );
      }
    }
    else {
      if ( log.isTraceEnabled() ) {
        log.trace(
            "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)
View Full Code Here

    //postDelete:
    // After actually deleting a row, record the fact that the instance no longer
    // exists on the database (needed for identity-column key generation), and
    // remove it from the session cache
    final PersistenceContext persistenceContext = session.getPersistenceContext();
    EntityEntry entry = persistenceContext.removeEntry( instance );
    if ( entry == null ) {
      throw new AssertionFailure( "possible nonthreadsafe access to session" );
    }
    entry.postDelete();

    EntityKey key = new EntityKey( entry.getId(), entry.getPersister(), session.getEntityMode() );
    persistenceContext.removeEntity(key);
    persistenceContext.removeProxy(key);
   
    if ( persister.hasCache() ) persister.getCacheAccessStrategy().remove( ck );
View Full Code Here

        values,
        source
    );
    Object version = Versioning.getVersion( values, persister );

    EntityEntry newEntry = source.getPersistenceContext().addEntity(
        object,
        Status.MANAGED,
        values,
        key,
        version,
View Full Code Here

    if ( !veto ) {
     
      persister.insert( id, state, instance, session );
   
      EntityEntry entry = session.getPersistenceContext().getEntry( instance );
      if ( entry == null ) {
        throw new AssertionFailure( "possible nonthreadsafe access to session" );
      }
     
      entry.postInsert();
 
      if ( persister.hasInsertGeneratedProperties() ) {
        persister.processInsertGeneratedProperties( id, instance, state, session );
        if ( persister.isVersionPropertyGenerated() ) {
          version = Versioning.getVersion(state, persister);
        }
        entry.postUpdate(instance, state, version);
      }
     
    }

    final SessionFactoryImplementor factory = getSession().getFactory();
View Full Code Here

        int entityState = -1;

        // 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.getEntityMode() );
          if ( id != null ) {
            EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
View Full Code Here

    // version be equivalent to the defined unsaved-value?
    return changed && existsInDatabase( target, source, persister );
  }

  private boolean existsInDatabase(Object entity, EventSource source, EntityPersister persister) {
    EntityEntry entry = source.getPersistenceContext().getEntry( entity );
    if ( entry == null ) {
      Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
      if ( id != null ) {
        EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
        Object managedEntity = source.getPersistenceContext().getEntity( key );
        entry = source.getPersistenceContext().getEntry( managedEntity );
      }
    }

    if ( entry == null ) {
      // perhaps this should be an exception since it is only ever used
      // in the above method?
      return false;
    }
    else {
      return entry.isExistsInDatabase();
    }
  }
View Full Code Here

    //safe from concurrent modification because of how entryList() is implemented on IdentityMap
    final int size = list.length;
    final Object anything = getAnything();
    for ( int i=0; i<size; i++ ) {
      Map.Entry me = list[i];
      EntityEntry entry = (EntityEntry) me.getValue();
      Status status = entry.getStatus();
      if ( status == Status.MANAGED || status == Status.SAVING ) {
        cascadeOnFlush( session, entry.getPersister(), me.getKey(), anything );
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.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.