/**
   * Commit the current transaction, writing any unflushed changes to the database.
   *
   * @throws IllegalStateException if isActive() is false.
   * @throws RollbackException if the commit fails.
   */
  public void commit() {
    assertActive();

    if (tx.getRollbackOnly()) {
      // This is thrown by the underlying transaction but we want to have a RollbackException here
      // so intercept it
      if (NucleusLogger.TRANSACTION.isDebugEnabled()) {
        NucleusLogger.TRANSACTION.debug(Localiser.msg("015020"));
      }
      throw new RollbackException(Localiser.msg("015020"));
    }

    try {
      tx.commit();
    } catch (NucleusTransactionException nte) {
      Throwable cause = nte.getCause();
      Throwable pe = null;
      if (cause instanceof NucleusException) {
        pe = NucleusJPAHelper.getJPAExceptionForNucleusException((NucleusException) cause);
      } else {
        pe = cause;
      }
      throw new RollbackException(Localiser.msg("015007"), pe);
    } catch (NucleusException ne) {
      throw NucleusJPAHelper.getJPAExceptionForNucleusException(ne);
    }
  }