9.7.5. Commit a Transaction
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.
Your datasource commits and your transaction ends, or an exception is thrown.
Note

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.