Package org.hibernate

Examples of org.hibernate.TransactionException


  /**
   * {@inheritDoc}
   */
  public void rollback() throws HibernateException {
    if (!begun) {
      throw new TransactionException("Transaction not successfully started");
    }

    log.debug("rollback");

    try {
      getTransaction().setRollbackOnly();
    }
    catch (SystemException se) {
      log.error("Could not set transaction to rollback only", se);
      throw new TransactionException("Could not set transaction to rollback only", se);
    }

    begun = false;

  }
View Full Code Here


    try {
      status = getTransaction().getStatus();
    }
    catch (SystemException se) {
      log.error("Could not determine transaction status", se);
      throw new TransactionException("Could not determine transaction status: ", se);
    }
    if (status==Status.STATUS_UNKNOWN) {
      throw new TransactionException("Could not determine transaction status");
    }
    else {
      return status==Status.STATUS_ACTIVE;
    }
  }
View Full Code Here

    try {
      status = getTransaction().getStatus();
    }
    catch (SystemException se) {
      log.error("Could not determine transaction status", se);
      throw new TransactionException("Could not determine transaction status", se);
    }
    if (status==Status.STATUS_UNKNOWN) {
      throw new TransactionException("Could not determine transaction status");
    }
    else {
      return JTAHelper.isRollback(status);
    }
  }
View Full Code Here

    try {
      status = getTransaction().getStatus();
    }
    catch (SystemException se) {
      log.error("Could not determine transaction status", se);
      throw new TransactionException("Could not determine transaction status: ", se);
    }
    if (status==Status.STATUS_UNKNOWN) {
      throw new TransactionException("Could not determine transaction status");
    }
    else {
      return status==Status.STATUS_COMMITTED;
    }
  }
View Full Code Here

  public void registerSynchronization(Synchronization sync) throws HibernateException {
    try {
      getTransaction().registerSynchronization(sync);
    }
    catch (Exception e) {
      throw new TransactionException("Could not register synchronization", e);
    }
  }
View Full Code Here

  public void begin() throws HibernateException {
    if (begun) {
      return;
    }
    if (commitFailed) {
      throw new TransactionException("cannot re-start transaction after failed commit");
    }

    log.debug("begin");

    try {
      toggleAutoCommit = jdbcContext.connection().getAutoCommit();
      if ( log.isDebugEnabled() ) {
        log.debug("current autocommit status: " + toggleAutoCommit);
      }
      if (toggleAutoCommit) {
        log.debug("disabling autocommit");
        jdbcContext.connection().setAutoCommit(false);
      }
    }
    catch (SQLException e) {
      log.error("JDBC begin failed", e);
      throw new TransactionException("JDBC begin failed: ", e);
    }

    callback = jdbcContext.registerCallbackIfNecessary();

    begun = true;
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public void commit() throws HibernateException {
    if (!begun) {
      throw new TransactionException("Transaction not successfully started");
    }

    log.debug("commit");

    if ( !transactionContext.isFlushModeNever() && callback ) {
      transactionContext.managedFlush(); //if an exception occurs during flush, user must call rollback()
    }

    notifyLocalSynchsBeforeTransactionCompletion();
    if ( callback ) {
      jdbcContext.beforeTransactionCompletion( this );
    }

    try {
      commitAndResetAutoCommit();
      log.debug("committed JDBC Connection");
      committed = true;
      if ( callback ) {
        jdbcContext.afterTransactionCompletion( true, this );
      }
      notifyLocalSynchsAfterTransactionCompletion( Status.STATUS_COMMITTED );
    }
    catch (SQLException e) {
      log.error("JDBC commit failed", e);
      commitFailed = true;
      if ( callback ) {
        jdbcContext.afterTransactionCompletion( false, this );
      }
      notifyLocalSynchsAfterTransactionCompletion( Status.STATUS_UNKNOWN );
      throw new TransactionException("JDBC commit failed", e);
    }
    finally {
      closeIfRequired();
    }
  }
View Full Code Here

   * {@inheritDoc}
   */
  public void rollback() throws HibernateException {

    if (!begun && !commitFailed) {
      throw new TransactionException("Transaction not successfully started");
    }

    log.debug("rollback");

    if (!commitFailed) {

      /*notifyLocalSynchsBeforeTransactionCompletion();
      if ( callback ) {
        jdbcContext.notifyLocalSynchsBeforeTransactionCompletion( this );
      }*/

      try {
        rollbackAndResetAutoCommit();
        log.debug("rolled back JDBC Connection");
        rolledBack = true;
        notifyLocalSynchsAfterTransactionCompletion(Status.STATUS_ROLLEDBACK);
      }
      catch (SQLException e) {
        log.error("JDBC rollback failed", e);
        notifyLocalSynchsAfterTransactionCompletion(Status.STATUS_UNKNOWN);
        throw new TransactionException("JDBC rollback failed", e);
      }
      finally {
        if ( callback ) {
          jdbcContext.afterTransactionCompletion( false, this );
        }
View Full Code Here

          //beforeCompletion() doesn't get called during rollback
    }
    catch (SystemException se) {
      log.error("could not determine transaction status", se);
      setRollbackOnly();
      throw new TransactionException("could not determine transaction status in beforeCompletion()", se);
    }
   
    try {
      if (flush) {
        log.trace("automatically flushing session");
View Full Code Here

    log.trace( "Attempting to locate UserTransaction via JNDI [{}]", utName );

    try {
      UserTransaction ut = ( UserTransaction ) getInitialContext().lookup( utName );
      if ( ut == null ) {
        throw new TransactionException( "Naming service lookup for UserTransaction returned null [" + utName +"]" );
      }

      log.trace( "Obtained UserTransaction" );

      return ut;
    }
    catch ( NamingException ne ) {
      throw new TransactionException( "Could not find UserTransaction in JNDI [" + utName + "]", ne );
    }
  }
View Full Code Here

TOP

Related Classes of org.hibernate.TransactionException

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.