9.7.5. Commit a Transaction

This procedure shows how to commit 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 commit a transaction, it must have been begun. Refer to Section 9.7.3, “Begin a Transaction” for information on beginning transactions.

  1. Call UserTransaction.commit().

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

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

Your datasource commits and your transaction ends, or an exception is thrown.

Note