3.4.8 Overview of processing and the points to remember when using the UserTransaction interface

If you use the UserTransaction interface, you can send the transaction start and conclusion instructions from the user program to the transaction manager. Use this method when you want to minutely control the transaction with the user program.

To send the transaction start and conclusion instructions from the user program to the transaction manager:

  1. Obtain the UserTransaction object.
    You obtain the UserTransaction object using one of the following methods:
    • Method of using the JNDI from the Naming Service and looking up "java:comp/UserTransaction"
    • Method of obtaining the UserTransaction object by invoking the getUserTransaction method of the EJBContext interface
    • Method of obtaining the UserTransaction object by using the DI
  2. Invoke the begin method of the UserTransaction object to start the transaction.
  3. Access the resources.
  4. Invoke the commit method or rollback method of the UserTransaction object to conclude the transaction.

The following figure shows the sequence for using the UserTransaction interface.

Figure 3-14 Sequence for using the UserTransaction interface

[Figure]

Remember the following points when you use the UserTransaction interface: