Package org.hibernate.engine

Examples of org.hibernate.engine.EntityEntry


    final boolean[] tableUpdateNeeded = getTableUpdateNeeded( dirtyFields, hasDirtyCollection );
    final int span = getTableSpan();

    final boolean[] propsToUpdate;
    final String[] updateStrings;
    EntityEntry entry = session.getPersistenceContext().getEntry( object );

    // Ensure that an immutable or non-modifiable entity is not being updated unless it is
    // in the process of being deleted.
    if ( entry == null && ! isMutable() ) {
      throw new IllegalStateException( "Updating immutable entity that is not in session yet!" );
View Full Code Here


      //
      // Note, it potentially could be a proxy, so doAfterTransactionCompletion 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

  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

    return sessionFactory.getCurrentSession();
  }
 
  private EntityStatus getStatus(Object model){
    SessionImpl simpl = (SessionImpl)getSession();   
    EntityEntry entry = simpl.getPersistenceContext().getEntry(model);
    if(entry != null){
      //Persistent Object
      logger.debug("current {} is one Entity with entry in PersistenceContext.", model);
      if (entry.getStatus() != Status.DELETED) {
        logger.debug("EntityStatus: {}", EntityStatus.PERSISTENT );
        return EntityStatus.PERSISTENT;
      } else {
        logger.debug("EntityStatus: {}", EntityStatus.REMOVED );
        return EntityStatus.REMOVED;
View Full Code Here

    return (Session)entityManager.getDelegate();
  }
 
  private EntityStatus getStatus(Object model){
    SessionImplementor simpl = (SessionImplementor)getSession();
    EntityEntry entry = simpl.getPersistenceContext().getEntry(model);
    if(entry != null){
      //Persistent Object
      logger.debug("current {} is one Entity with entry in PersistenceContext.", model);
      if (entry.getStatus() != Status.DELETED) {
        logger.debug("EntityStatus: {}", EntityStatus.PERSISTENT );
        return EntityStatus.PERSISTENT;
      } else {
        logger.debug("EntityStatus: {}", EntityStatus.REMOVED );
        return EntityStatus.REMOVED;
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

   * @param session The session from which the request is originating.
   * @return The collection owner's key
   */
  public Serializable getKeyOfOwner(Object owner, SessionImplementor session) {
   
    EntityEntry entityEntry = session.getPersistenceContext().getEntry( owner );
    if ( entityEntry == null ) return null; // This just handles a particular case of component
                    // projection, perhaps get rid of it and throw an exception
   
    if ( foreignKeyPropertyName == null ) {
      return entityEntry.getId();
    }
    else {
      // TODO: at the point where we are resolving collection references, we don't
      // know if the uk value has been resolved (depends if it was earlier or
      // later in the mapping document) - now, we could try and use e.getStatus()
      // to decide to semiResolve(), trouble is that initializeEntity() reuses
      // the same array for resolved and hydrated values
      Object id;
      if ( entityEntry.getLoadedState() != null ) {
        id = entityEntry.getLoadedValue( foreignKeyPropertyName );
      }
      else {
        id = entityEntry.getPersister().getPropertyValue( owner, foreignKeyPropertyName, session.getEntityMode() );
      }

      // NOTE VERY HACKISH WORKAROUND!!
      // TODO: Fix this so it will work for non-POJO entity mode
      Type keyType = getPersister( session ).getKeyType();
      if ( !keyType.getReturnedClass().isInstance( id ) ) {
        id = (Serializable) keyType.semiResolve(
            entityEntry.getLoadedValue( foreignKeyPropertyName ),
            session,
            owner
          );
      }

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
        // TODO: cache the entity name somewhere so that it is available to this exception
        log.trace( "transient instance could not be processed by merge: " +
            event.getSession().guessEntityName( copy ) + "[" + entity + "]" );
        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 );
      if ( entity == event.getEntity() ) {
        mergeTransientEntity( entity, copyEntry.getEntityName(), event.getRequestedId(), event.getSession(), copyCache);
      }
      else {
        mergeTransientEntity( entity, copyEntry.getEntityName(), copyEntry.getId(), event.getSession(), copyCache);
      }
    }
  }
View Full Code Here

        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

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.