Package org.hibernate.engine

Examples of org.hibernate.engine.EntityEntry


        event.setEntity( entity );
        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


    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

   
    Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
    //TODO: if object was an uninitialized proxy, this is inefficient,
    //      resulting in two SQL selects
   
    EntityEntry entry = source.getPersistenceContext().getEntry(entity);
    if (entry==null) {
      final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
      final Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
      if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) {
        throw new TransientObjectException(
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

    for ( int i = 0; i < size; i++ ) {

      // Update the status of the object and if necessary, schedule an update

      Map.Entry me = list[i];
      EntityEntry entry = (EntityEntry) me.getValue();
      Status status = entry.getStatus();

      if ( status != Status.LOADING && status != Status.GONE ) {
        FlushEntityEvent entityEvent = new FlushEntityEvent( source, me.getKey(), entry );
        FlushEntityEventListener[] listeners = source.getListeners().getFlushEntityEventListeners();
        for ( int j = 0; j < listeners.length; j++ ) {
View Full Code Here

  public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session)
      throws HibernateException {

    final Serializable id = session.getContextEntityIdentifier( entity );

    final EntityEntry entry = session.getPersistenceContext().getEntry( entity );
    if ( entry == null ) {
      throw new HibernateException( "entity is not associated with the session: " + id );
    }

    if ( log.isTraceEnabled() ) {
View Full Code Here

      //
      // Note, it potentially could be a proxy, so perform the location the safe way...
      EntityKey key = new EntityKey( id, this, session.getEntityMode() );
      Object entity = session.getPersistenceContext().getEntity( key );
      if ( entity != null ) {
        EntityEntry entry = session.getPersistenceContext().getEntry( entity );
        loadedState = entry.getLoadedState();
      }
    }

    final String[] deleteStrings;
    if ( isImpliedOptimisticLocking && loadedState != null ) {
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 ) {
        persistenceContext.removeEntity( e.getEntityKey() );
        doEvict( object, e.getEntityKey(), e.getPersister(), source );
      }
    }
  }
View Full Code Here

  }

  protected Serializable entityIsPersistent(SaveOrUpdateEvent event) throws HibernateException {
    log.trace( "ignoring persistent instance" );

    EntityEntry entityEntry = event.getEntry();
    if ( entityEntry == null ) {
      throw new AssertionFailure( "entity was transient or detached" );
    }
    else {

      if ( entityEntry.getStatus() == Status.DELETED ) {
        throw new AssertionFailure( "entity was deleted" );
      }

      final SessionFactoryImplementor factory = event.getSession().getFactory();

      Serializable requestedId = event.getRequestedId();

      Serializable savedId;
      if ( requestedId == null ) {
        savedId = entityEntry.getId();
      }
      else {

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

        savedId = requestedId;

      }

      if ( log.isTraceEnabled() ) {
        log.trace(
            "object already associated with session: " +
                MessageHelper.infoString( entityEntry.getPersister(), savedId, factory )
        );
      }

      return savedId;
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.