How to use JTA transactions with BTM in Spring
This howto is intended for developers using Spring wanting to take advantage of distributed transactions when using JDBC code.
Spring and BTM versions used in this document:
- Spring 2.x
- BTM 1.0
Database used for this document:
- Derby version 10.2.2.0
- This requires JDK 1.5+
Project directory structure
Here are the folders you first need to create:
Below is a list of required jars. You have to copy them under the
You need to create two databases, each one with a single users table.
To do so, create the file
PROJECT_HOME/derby-create.sql with this content:
Then run this command:
Create a file named
beans.xml in the
PROJECT_HOME/ folder with this content:
Create these Java classes in the
PROJECT_HOME/src/jtatest folder. Note: this code isn't anywhere near production ready - it's only supposed to be used as a simple test !
Now you have to run those commands from the
Compile these classes using this command line:
Lastly, run your application using this command line: