5

I have some confusion on using JTA within the Spring Framework on Apache Tomcat and i hope someone will clarify as after many research i can't seem to find the correct answer as of yet.

I am developing a web application using Spring Framework to be running on Apache Tomcat 6.

I read somewhere that Spring's does support for JTA but it delegates to the underlying JavaEE application server. Now this is where i am confused because i Tomcat is not a full JavaEE application server - it is merely a servlet container and as i believe it doesn't provide JTA implementation like the full JavaEE application server (Glassfish/Wildfly etc...) does.

But when i do something like the following the transaction aspect of it works:

@Transactional
public class ServiceClassImpl implements ServiceInterface {
// code here that involves transactions e.g. calling DAO code
...
}

So, i'm confused. I hope someone will enlighten me.

f_puras
  • 2,521
  • 4
  • 33
  • 38
SoftwareDeveloper
  • 1,094
  • 2
  • 15
  • 26
  • possible duplicate of [How to use JTA support in Tomcat 6 for Hibernate?](http://stackoverflow.com/questions/2552612/how-to-use-jta-support-in-tomcat-6-for-hibernate) – seenukarthi Jul 26 '15 at 06:55
  • Similar ingredients but different recipe. I think that question asks how to use JTA on Tomcat 6. Whereas my question is questioning whether or not Tomcat 6 already allows JTA - because when i use the JavaEE @Transactional annotation - it works – SoftwareDeveloper Jul 26 '15 at 08:00
  • What does the fact that your code works have to do with JTA? – a better oliver Jul 26 '15 at 09:08
  • 1
    You shouldn't be developing anything new in 2015 to be running in Tomcat 6. You're two major version out of date. – user207421 Jul 26 '15 at 11:12
  • @zeroflagL maybe that's the answer to my question. The fact that using javax.transaction.transactional annotation works maybe implies it has no relation to JTA but maybe the underlying JDBC local transactions. – SoftwareDeveloper Jul 26 '15 at 14:32
  • @EJP good point but only if i had a choice – SoftwareDeveloper Jul 26 '15 at 14:35
  • I see. JTA provides some more sophisticated features, but ordinary transactions are indeed always available. – a better oliver Jul 26 '15 at 14:38
  • It's part of your job to evaluate your costs of complying with these constraints as you encounter them. Not just to accept them blindly. The fact that the annotations compile doesn't prove anything about what Tomcat supports. – user207421 Jul 27 '15 at 11:02

3 Answers3

4

The answer is: NO. Tomcat 6.x (7&8) don't provide JTA out-of-the-box because they don't have a transaction manager which is required as a separate component to monitor multiple resources (e.g. datasources).

The mentioned answer How to use JTA support in Tomcat 6 for Hibernate? already gives a list of additional JTA transaction managers that can be used alongside Tomcat.

Spring supports declarative transaction management via a platform transaction manager (TM) and provides some implementations (e.g. datasources) that make @Transactional work on a single resource without the additional TM.

Understanding the Spring Framework transaction abstraction provides more details and Spring Boot can be easily configured to run Atomikos or Bitronix Transaction managers on the embedded Tomcat.

Community
  • 1
  • 1
real_paul
  • 574
  • 2
  • 22
0

JTA provides you with distributed transactions support, but if JTA is not available like in Tomcat, you still can use local JDBC transactions.

xeye
  • 1,250
  • 10
  • 15
0

YES :-)

JTA can be used in Tomcat, for instance via https://www.atomikos.com

The trick is to use a componentized JTA implementation.

Cheers

Guy Pardon
  • 484
  • 2
  • 8