Package org.hibernate

Examples of org.hibernate.TransactionException


    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

      return JTAHelper.isTransactionInProgress(
          transactionContext.getFactory().getTransactionManager().getTransaction()
      );
    }
    catch( SystemException se ) {
      throw new TransactionException( "Unable to check transaction status", se );
    }

  }
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 {
      newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
      if ( newTransaction ) {
        userTransaction.begin();
        log.debug( "Began a new JTA transaction" );
      }
    }
    catch ( Exception e ) {
      log.error( "JTA transaction begin failed", e );
      throw new TransactionException( "JTA transaction begin failed", e );
    }

    /*if (newTransaction) {
      // don't need a synchronization since we are committing
      // or rolling back the transaction ourselves - assuming
View Full Code Here

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

    log.debug( "commit" );

    boolean flush = !transactionContext.isFlushModeNever()
        && ( callback || !transactionContext.isFlushBeforeCompletionEnabled() );

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

    if ( callback && newTransaction ) {
      jdbcContext.beforeTransactionCompletion( this );
    }

    closeIfRequired();

    if ( newTransaction ) {
      try {
        userTransaction.commit();
        commitSucceeded = true;
        log.debug( "Committed JTA UserTransaction" );
      }
      catch ( Exception e ) {
        commitFailed = true; // so the transaction is already rolled back, by JTA spec
        log.error( "JTA commit failed", e );
        throw new TransactionException( "JTA commit failed: ", e );
      }
      finally {
        afterCommitRollback();
      }
    }
View Full Code Here

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

    log.debug( "rollback" );

    try {
      closeIfRequired();
    }
    catch ( Exception e ) {
      // swallow it, and continue to roll back JTA transaction
      log.error( "could not close session during rollback", e );
    }

    try {
      if ( newTransaction ) {
        if ( !commitFailed ) {
          userTransaction.rollback();
          log.debug( "Rolled back JTA UserTransaction" );
        }
      }
      else {
        userTransaction.setRollbackOnly();
        log.debug( "set JTA UserTransaction to rollback only" );
      }
    }
    catch ( Exception e ) {
      log.error( "JTA rollback failed", e );
      throw new TransactionException( "JTA rollback failed", e );
    }
    finally {
      afterCommitRollback();
    }
  }
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.