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:
- 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
- Invoke the begin method of the UserTransaction object to start the transaction.
- Access the resources.
- 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]](figure/zu031300.gif)
Remember the following points when you use the UserTransaction interface:
- To use the UserTransaction interface, specify Bean in the <transaction-type> tag of the DD. You can also specify the definition in an annotation without using the DD. For details on annotations, see 2. Annotations and Dependency Injection supported by Application Server in the uCosminexus Application Server API Reference Guide.
- When you access the resources after the transaction is started, the resource access transactions are automatically managed.
- To access multiple resources after the transaction starts, you must use a resource adapter that supports the global transactions, and set the transaction support level of the resource adapter to XATransaction.
- The UserTransaction interface can be used with Enterprise Beans, servlets, and JSPs.
- A transaction that is started with the user program by using the UserTransaction interface must be concluded by issuing commit or rollback with the user program even if an exception occurs. If the transaction is not concluded, problems, such as the resource lock is not released, or the subsequent transactions cannot be started, might occur.