• 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 ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

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.
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
    Bookmark Topic Watch Topic
  • New Topic