This sample application demonstrates the use of an external JTA transaction manager in a Spring Data JPA application. It uses two database schemas, saving data to and reading from these schemas, as needed to demonstrate and test the use of JTA transactions.
The steps below outline how the JTA transaction manager is configured:
- One or more XA-compliant data source that will manage the underlying data store.
Most libraries provide XA-compliant versions of their drivers. For example, the class
org.h2.Driver
is the regular (non-XA) JDBC driver for the H2 in-memory database. The XA-compliant data source for the same database is provided by the classorg.h2.jdbcx.JdbcDataSource
. Similarly, wherecom.mysql.jdbc.Driver
is the regular JDBC driver class for the MySQL database,com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
provides the XA-compliant data source. - Point the
EntityManagerFactory
instance to the XADataSource
instance. This makes sure that the database connections participate in JTA transactions. - Declare an XA transaction manager and an XA user transaction.
- Wrap the XA transaction manager in a Spring
JtaTransactionManager
. - Use the Spring
JtaTransactionManager
.
Atomikos TransactionEssentials is
a JTA transaction manager that comes in both open-source and commercial flavours. The
open-source version of Atomikos is included with this application. To see Atomikos in action,
run the bundled integration test as mvn clean test -D"spring.profiles.active=atomikos"
.
The open-source version of Atomikos used for this application is available under the Apache License v2.0. Full licensing details are available on the Atomikos website.
Bitronix Transaction Manager is a fully open-source
JTA transaction manager. Run the bundled integration tests as
mvn clean test -D"spring.profiles.active=bitronix"
to see Bitronix in action.
The Bitronix version used for this application is available under the GNU Lesser General Public License v3.0. Full licensing details are available on Bitronix's Github repository.
JBoss Transaction Server (JBossTS) was an open-source JTA transaction manager that
used to ship as part of the JBoss J2EE Application Server.
Run the bundled integration tests as
mvn clean test -D"spring.profiles.active=jbossts"
to see JBossTS in action.
The JBossTS version used for this application is available under the GNU Lesser General Public License v2.1.
This sample application and its associated source code in its entirety is being made available under the following licensing terms.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.