9.7.6. Roll Back a Transaction

This procedure shows how to roll back a JTA transaction, whether it is local or distributed, using the Java Transaction Service (JTS). To use distributed transactions, you need to configure the ORB. Refer to the ORB Configuration section of the Administration and Configuration Guide for more information on ORB configuration.
Task Prerequisites

Before you can roll back a transaction, it must have been begun. For information about beginning a transaction, see Section 9.7.3, “Begin a Transaction”.

  1. Call UserTransaction.rollback().

    When you call method UserTransaction.rollback(), the Transaction Manager attempts to roll back the transaction.
     ...
    UserTransaction.rollback();
    catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
    
  2. If you are using an EJB, you do not need to manually roll back.

    If you use an EJB, you do not need to call rollback(), because the container handles the transaction lifecycle.
Result:

Your transaction is rolled back by the Transaction Manager.

Note