Support for XA and non-XA resources in a single JTA transaction in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 4
- 5
- 6
- 7
Issue
- Using both XA and non-XA datasources in a single transaction
Resolution
Whether or not resources need to support XA depends on what the transaction is doing.
Using a Single Non-XA Resource
A JTA transaction (e.g. one started inside an EJB) supports XA.
One and only one resource in a transaction always results in a 1pc operation so it doesn't really matter if such a resource supports XA or not.
One may enlist a single non-XA resource (e.g. a <local-tx-datasource>) in a JTA transaction with one or more XA resources (e.g. <xa-datasource>). This is made possible by a transaction manager optimization called the "Last Resource Commit Optimization" (LRCO).
Note that LRCO is not recommended as it isn't true XA and is, therefore, transactionally unsafe. For example, in a scenario where commit succeeds for the non-XA resource but the system crashes before commit of the XA resources, the prepared XA transaction(s) will be rolled back leaving the backing datasources in an inconsistent state. For this reason, one should only use the LRCO when absolutely necessary (e.g. when using legacy resources that cannot be changed, etc.). EAP 6.3 and later releases include the more robust CMR option ( see This content is not included.section 11.3, Development Guide).
Using Multiple Non-XA Resources
It is forbidden to enlist more than one non-XA resource in a transaction unless the transaction manager's configuration is explicitly overridden by use of the allowMultipleLastResources property. Note: The configuration below is considered extremely unsafe as it will almost certainly result in heuristic outcomes (i.e. outcomes where data is not consistent between the resources) and is not recommended for use in production systems.
EAP 6 and Later
The following may be added to the system-properties section in the [standalone|domain].xml
<!-- This is not recommended for use in a production system as it is transactionally unsafe -->
<property name="com.arjuna.ats.arjuna.allowMultipleLastResources" value="true"/>
Prior to EAP 6
Adding the below property in the "jta" section of <JBOSS_HOME>/server/<profile>/conf/jboss[jta|ts]-properties.xml will allow multiple 1pc resources to be enlisted in an XA transaction:
<!-- This is not recommended for use in a production system as it is transactionally unsafe -->
<property name="com.arjuna.ats.jta.allowMultipleLastResources" value="true"/>
Additional References
- ARJUNA012140: Adding multiple last resources is disallowed
- ARJUNA012141: Multiple last resources have been added to the current transaction. This is transactionally unsafe ...
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.