Using JTA transactions in EJBs
How to use JTA transactions in Enterprise JavaBeans (EJBs) on Liberty.
About this task
EJBs are Java™ objects that are managed by the Liberty JVM server, allowing a modular architecture of Java applications. The Liberty JVM server supports EJB Lite 3.1 and EJB Lite 3.2, and EJB 3.2. EJBs are deployed to a Liberty server using an enterprise application archive (EAR) file created from an enterprise application project. Enterprise application projects can contain both EJB and Web projects.
EJB Lite is enabled by adding the relevant feature ejbLite-3.1 or ejbLite-3.2 to the server.xml configuration file. EJB is enabled by adding ejb-3.2 to the server.xml configuration file. EJBs are deployed into a container. This container works in the background ensuring that aspects like session management, transactions and security are adhered to.
- Mandatory
- Required
- RequiresNew
- Supports
- NotSupported
- Never
| Transaction Attribute | No JTA transaction | Pre-existing JTA transaction | Accessing a remote EJB with a pre-existing JTA transaction | Exception behavior |
|---|---|---|---|---|
| Mandatory | Throws exception EJBTransactionRequiredException. | Inherits the existing JTA transaction. | Throws exception com.ibm.websphere.csi.CSITransactionMandatoryException. | Rollback |
| Required | EJB container creates new JTA transaction. | Inherits the existing JTA transaction. | Throws exception com.ibm.websphere.csi.CSITransactionRequiredException. | Rollback |
| RequiresNew | EJB container creates new JTA transaction. | Throws exception javax.ejb.EJBException. | EJB container creates a new JTA transaction that is managed by the remote server. | Rollback |
| Supports | Continues without a JTA transaction. | Inherits the existing JTA transaction. | Throws exception com.ibm.websphere.csi.CSITransactionSupportedException. | Rollback if called from JTA |
| NotSupported | Continues without a JTA transaction. | Suspends the JTA transaction but not the CICS UOW. | The remote server continues without a JTA transaction. | No rollback |
| Never | Continues without a JTA transaction. | Throws exception javax.ejb.EJBException. | The remote server continues without a JTA transaction. | No rollback |
- The transaction attribute NotSupported cannot be supported by a CICS Liberty JVM server. Calling a method marked as NotSupported will suspend the JTA transaction but not suspend the CICS UOW. Any modification of CICS resources during this method call will still be recoverable.
- The transaction attribute RequiresNew is supported by a CICS Liberty JVM server, with the restriction that the CICS UOW cannot be nested. Attempting to call a method marked as RequiresNew when already in a JTA transaction will cause an exception to be thrown.