| Author |
does Spring handle JTA kind stuff ?
|
ben oliver
Ranch Hand
Joined: Mar 28, 2006
Posts: 356
|
|
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) ?
|
 |
Chris Mathews
Ranch Hand
Joined: Jul 18, 2001
Posts: 2712
|
|
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.
|
 |
 |
|
|
subject: does Spring handle JTA kind stuff ?
|
|
|