• 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Transaction Management in Spring

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone ,

I am new to spring Framework and I am a bit confused with the Transaction Management provided by Spring .Can anyone tell me what is the difference between using

as transaction managers and how the scope of transaction changes after using them ?

Thanks in advance
Ranch Hand
Posts: 15304
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cookie doon

We don't have too many rules around these parts, but we do have a Naming Policy. Please adjust your display name by clicking the My Profile link accordingly.

Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your application implements usecases that require support for global transactions (like moving data between two or more databases, or from a queue to a database, etc) then you need to run your app within an environment wich provides support for distributed transactions. Application servers are the usual candidates for such requirements since they implement the 2PC protocol out of the box. The second thing your application needs is to get �a handle� on the transaction manager in order to globally demarcate your transactions. As an example consider the EJB programmers using BMT for implementing the transaction management. They will lookup up the UserTransaction object from jndi and will call methods like begin(), commit(), rollback() etc. Obviously Spring applications usually don�t know (and they shouldn�t) about the transaction manager used. Besides the whole point here is to use declarative security with Spring (via AOP).
That being said all you need to do is to tell spring about the transaction manager it should use to demarcate your transactions (AOP instead will border your code with similar code that the EJB-BMT programmers use). The org.springframework.transaction.jta.JtaTransactionManager should be used when you intend to use global transactions. Here there is a configuration snippet I use with WAS (I hope it is self descriptive):

However not all applications have a need for global transactions. Many of them will only require managing data within a single persistence storage. If that�s the case you could also chouse to use org.springframework.jdbc.datasource.DataSourceTransactionManager
As for the last one org.springframework.orm.hibernate.HibernateTransactionManager this works best with Hibernate applications (Spring integrates great with Hibernate). This also doesn�t provide support for global transactions. In a way you could think about this manager like a Hibernate customized version of the DataSourceTransactionManager.

So I left, I came home, and I ate some pie. And then I read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!