Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

does Spring handle JTA kind stuff ?

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some JTA code and now I am thinking about using Spring --

1) can I keep JTA while I use Spring ?

2) Does Spring have any built-in features that handle things as JTA can handle (so I can get rid of JTA) ?
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, I have to ask what are you are using JTA for? In my experiences, I find most people that are using JTA don't really even need it. It is one of those 1% solutions... the rest of the 99% of devleopers don't have real requirements for it.

That said... Spring's Transaction Management doesn't try to replace JTA but it does integrate nicely with it if that is what you need. You just declare a JtaTransactionManager:


Then proxy your DAOs (or whatever you are using) with TransactionProxyFactoryBean like this (notice with are wiring in the above transactionManager bean):


This example is of course not complete since Spring is expecting a bean definition "sampleDaoTarget" for your DAO implementation and a bean definition "transactionAttributeSource" to describe what propagation behavior to use for the transaction management. These definitions would look similar to:


What this basically does is tell Spring to mark every method in SampleDao as PROPAGATION_REQUIRED which behaves the same way as the REQUIRED transaction attribute in EJB. You can get a lot more granular with deciding what methods to apply what transaction attributes to using some of the other TransactionAttributeSource classes in Spring. You can even declare transaction support via Java 1.5 Annotations if that is of interest to you... I just tried to keep this example as basic as possible since Spring can be a bit overwelming to being with.
 
I am going to test your electrical conductivity with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!