Package org.hibernate.engine

Examples of org.hibernate.engine.EntityEntry


    catch (PropertyValueException ex) {
      String propertyName = ex.getPropertyName();
      Object propertyFromCopy = persister.getPropertyValue( copy, propertyName, source.getEntityMode() );
      Object propertyFromEntity = persister.getPropertyValue( entity, propertyName, source.getEntityMode() );
      Type propertyType = persister.getPropertyType( propertyName );
      EntityEntry copyEntry = source.getPersistenceContext().getEntry( copy );
      if ( propertyFromCopy == null || ! propertyType.isEntityType() ) {
        log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
            "' is null or not an entity; " + propertyName + " =["+propertyFromCopy+"]");
        throw ex;
      }
      if ( ! copyCache.containsKey( propertyFromEntity ) ) {
        log.trace( "property '" + copyEntry.getEntityName() + "." + propertyName +
            "' from original entity is not in copyCache; " + propertyName + " =["+propertyFromEntity+"]");
        throw ex;
      }
      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


    // 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

    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

  protected static Serializable getLoadedOwnerIdOrNull( PersistentCollection collection, EventSource source ) {
    return source.getPersistenceContext().getLoadedCollectionOwnerIdOrNull( collection );
  }

  protected static Serializable getOwnerIdOrNull( Object owner, EventSource source ) {
    EntityEntry ownerEntry = source.getPersistenceContext().getEntry( owner );
    return ( ownerEntry == null ? null : ownerEntry.getId() );
  }
View Full Code Here

    // collectionPersister should not be null, but we don't want to throw
    // an exception if it is null
    String entityName =
        ( collectionPersister == null ? null : collectionPersister.getOwnerEntityPersister().getEntityName() );
    if ( affectedOwner != null ) {
      EntityEntry ee = source.getPersistenceContext().getEntry( affectedOwner );
      if ( ee != null && ee.getEntityName() != null) {
        entityName = ee.getEntityName();
      }
    } 
    return entityName;
  }
View Full Code Here

public class DefaultSaveEventListener extends DefaultSaveOrUpdateEventListener {

  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 && entry.getStatus() != Status.DELETED ) {
      return entityIsPersistent(event);
    }
    else {
      return entityIsTransient(event);
    }
View Full Code Here

    EventSource eventSource = event.getSession();
    handlePostUpdate(entity, eventSource);
  }

  private void handlePostUpdate(Object entity, EventSource source) {
    EntityEntry entry = (EntityEntry) source.getPersistenceContext()
        .getEntityEntries().get(entity);
    // mimic the preUpdate filter
    if (Status.DELETED != entry.getStatus()) {
      callbackHandler.postUpdate(entity);
    }
  }
View Full Code Here

      persistenceContext.removeProxy( key );

      if ( !li.isUninitialized() ) {
        final Object entity = persistenceContext.removeEntity( key );
        if ( entity != null ) {
          EntityEntry e = event.getSession().getPersistenceContext().removeEntry( entity );
          doEvict( entity, key, e.getPersister(), event.getSession() );
        }
      }
      li.unsetSession();
    }
    else {
      EntityEntry e = persistenceContext.removeEntry( object );
      if ( e != null ) {
        EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode()  );
        persistenceContext.removeEntity( key );
        doEvict( object, key, e.getPersister(), source );
      }
    }
  }
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

    for ( Iterator it=copyCache.values().iterator(); it.hasNext(); ) {
      Object entity = it.next();
      if ( entity instanceof HibernateProxy ) {
        entity = ( (HibernateProxy) entity ).getHibernateLazyInitializer().getImplementation();
      }
      EntityEntry entry = event.getSession().getPersistenceContext().getEntry( entity );
      if ( entry == null ) {
        throw new TransientObjectException(
            "object references an unsaved transient instance - save the transient instance before merging: " +
            event.getSession().guessEntityName( entity )
        );
        // TODO: cache the entity name somewhere so that it is available to this exception
        // entity name will not be available for non-POJO entities
      }
      if ( entry.getStatus() != Status.MANAGED ) {
        throw new AssertionFailure( "Merged entity does not have status set to MANAGED; "+entry+" status="+entry.getStatus() );
      }
    }
  }
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.