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.
Call
UserTransaction
.commit()
.When you call methodUserTransaction
.commit()
, the Transaction Manager attempts to commit the transaction.... UserTransaction.commit(); catch (Exception ex) { ex.printStackTrace(); System.exit(0); }
If you are using an EJB, you do not need to manually commit.
If you use an EJB, you do not need to callcommit()
, because the container handles the transaction lifecycle.
Result:
Your datasource commits and your transaction ends, or an exception is thrown.
Note
For a full example, see Section 9.9.3, “JTA Transaction Example”.