Package org.hibernate

Examples of org.hibernate.LazyInitializationException


            throwLazyInitializationException("session is disconnected");
    }   
  }
 
  private void throwLazyInitializationException(String message) {
    throw new LazyInitializationException(
        "failed to lazily initialize a collection" +
        ( role==null "" : " of role: " + role ) +
        ", " + message
      );
  }
View Full Code Here


      if ( specjLazyLoad ) {
        session = openTemporarySessionForLoading();
        isTempSession = true;
      }
      else {
        throw new LazyInitializationException( "could not initialize proxy - no Session" );
      }
    }
    else if ( !session.isOpen() ) {
      if ( specjLazyLoad ) {
        originalSession = session;
        session = openTemporarySessionForLoading();
        isTempSession = true;
      }
      else {
        throw new LazyInitializationException( "could not initialize proxy - the owning Session was closed" );
      }
    }
    else if ( !session.isConnected() ) {
      if ( specjLazyLoad ) {
        originalSession = session;
        session = openTemporarySessionForLoading();
        isTempSession = true;
      }
      else {
        throw new LazyInitializationException( "could not initialize proxy - the owning Session is disconnected" );
      }
    }

    if ( isTempSession ) {
      // TODO: On the next major release, add an
View Full Code Here

      throwLazyInitializationException( "session is disconnected" );
    }
  }

  private void throwLazyInitializationException(String message) {
    throw new LazyInitializationException(
        "failed to lazily initialize a collection" +
            (role == null ? "" : " of role: " + role) +
            ", " + message
    );
  }
View Full Code Here

      // while constructor is running
      if ( method.getName().equals( "getHibernateLazyInitializer" ) ) {
        return this;
      }
      else {
        throw new LazyInitializationException( "unexpected case hit, method=" + method.getName() );
      }
    }
  }
View Full Code Here

      // while constructor is running
      if ( method.getName().equals( "getHibernateLazyInitializer" ) ) {
        return this;
      }
      else {
        throw new LazyInitializationException( "unexpected case hit, method=" + method.getName() );
      }
    }
  }
View Full Code Here

    if ( !initialized ) {
      if ( allowLoadOutsideTransaction ) {
        permissiveInitialization();
      }
      else if ( session == null ) {
        throw new LazyInitializationException( "could not initialize proxy - no Session" );
      }
      else if ( !session.isOpen() ) {
        throw new LazyInitializationException( "could not initialize proxy - the owning Session was closed" );
      }
      else if ( !session.isConnected() ) {
        throw new LazyInitializationException( "could not initialize proxy - the owning Session is disconnected" );
      }
      else {
        target = session.immediateLoad( entityName, id );
        initialized = true;
        checkTargetState();
View Full Code Here

  protected void permissiveInitialization() {
    if ( session == null ) {
      //we have a detached collection thats set to null, reattach
      if ( sessionFactoryUuid == null ) {
        throw new LazyInitializationException( "could not initialize proxy - no Session" );
      }
      try {
        SessionFactoryImplementor sf = (SessionFactoryImplementor)
            SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid );
        SessionImplementor session = (SessionImplementor) sf.openSession();
        session.getPersistenceContext().setDefaultReadOnly( true );
        session.setFlushMode( FlushMode.MANUAL );

        boolean isJTA = session.getTransactionCoordinator()
            .getTransactionContext().getTransactionEnvironment()
            .getTransactionFactory()
            .compatibleWithJtaSynchronization();
       
        if ( !isJTA ) {
          // Explicitly handle the transactions only if we're not in
          // a JTA environment.  A lazy loading temporary session can
          // be created even if a current session and transaction are
          // open (ex: session.clear() was used).  We must prevent
          // multiple transactions.
          ( ( Session) session ).beginTransaction();
        }

        try {
          target = session.immediateLoad( entityName, id );
        }
        finally {
          // make sure the just opened temp session gets closed!
          try {
            if ( !isJTA ) {
              ( ( Session) session ).getTransaction().commit();
            }
            ( (Session) session ).close();
          }
          catch (Exception e) {
            log.warn( "Unable to close temporary session used to load lazy proxy associated to no session" );
          }
        }
        initialized = true;
        checkTargetState();
      }
      catch (Exception e) {
        e.printStackTrace();
        throw new LazyInitializationException( e.getMessage() );
      }
    }
    else if ( session.isOpen() && session.isConnected() ) {
      target = session.immediateLoad( entityName, id );
      initialized = true;
      checkTargetState();
    }
    else {
      throw new LazyInitializationException( "could not initialize proxy - Session was closed or disced" );
    }
  }
View Full Code Here

      throwLazyInitializationException( "session is disconnected" );
    }
  }

  private void throwLazyInitializationException(String message) {
    throw new LazyInitializationException(
        "failed to lazily initialize a collection" +
            (role == null ? "" : " of role: " + role) +
            ", " + message
    );
  }
View Full Code Here

      if ( specjLazyLoad ) {
        session = openTemporarySessionForLoading();
        isTempSession = true;
      }
      else {
        throw new LazyInitializationException( "could not initialize proxy - no Session" );
      }
    }
    else if ( !session.isOpen() ) {
      if ( specjLazyLoad ) {
        originalSession = session;
        session = openTemporarySessionForLoading();
        isTempSession = true;
      }
      else {
        throw new LazyInitializationException( "could not initialize proxy - the owning Session was closed" );
      }
    }
    else if ( !session.isConnected() ) {
      if ( specjLazyLoad ) {
        originalSession = session;
        session = openTemporarySessionForLoading();
        isTempSession = true;
      }
      else {
        throw new LazyInitializationException( "could not initialize proxy - the owning Session is disconnected" );
      }
    }

    if ( isTempSession ) {
      session.getPersistenceContext().addUninitializedDetachedCollection(
View Full Code Here

      throwLazyInitializationException( "session is disconnected" );
    }
  }

  private void throwLazyInitializationException(String message) {
    throw new LazyInitializationException(
        "failed to lazily initialize a collection" +
            (role == null ? "" : " of role: " + role) +
            ", " + message
    );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.LazyInitializationException

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.