3

I have a class that is annotated with @Service. I have a method that should update two different data sources (database and a content repository). I have added @Transactional over the method in the service class. Without any further customizations; is it correct that the two repository classes (annotated with @Repository) is runned within the same transaction?

I am using JBoss 7.1.1 and I have these two lines in the Spring (3.2) config:

<tx:jta-transaction-manager/>
<tx:annotation-driven proxy-target-class="true"/>

Or does this run in two different transactions? I want to only commit the data when no runtime exceptions is thrown inside the service layer method. It is invoked from a controller method (class annotated with @Controller).

I will add 500 bounty as soon as possible to the guy that helps me get Jackrabbit and a database connection to run in the same transaction. I am using JBoss 7.1.1, Spring 3.2, Jackrabbit 2.6.2 JCA.

LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • Your configuration should be enough as spring will take the required beans from jndi, but JTA is usually a PITA. I just suggest you to test partial failures with both of the datasources and also app crashes, as JTA transactions are not that easy to recover and you might need to perform some manual actions to *delete* the partial transaction from the transaction manager and databases – Augusto Sep 06 '13 at 12:55

1 Answers1

0

Without any further customizations, the two repository classes will run in different transactions.

What you are looking for is called a Distributed Transaction, there are StackOverflow answers about that here and here. If you are not running in a Java EE server, here is an article that describes setting up distributed transactions for a plain servlet container like Tomcat.

Community
  • 1
  • 1
Jason
  • 7,356
  • 4
  • 41
  • 48