Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction related question in Spring Hibernate Application

 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Spring Hibernate applications. I have a query regarding transaction management in an application. I have gone through Spring and Hibernate documentation and found that both provide transaction support. For Example, Spring provides transaction support through AOP and Hibernate provides transaction support through Transaction interface. So, if we are using both the frameworks in a web-application, what is the best way to implement transaction management? What are the pros/cons of the apporaches?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you go through the Spring documentation again they have an entire section on transaction management. Besides explaining how it works they also specify the many advantages.

2 of my favorites are:

1. Declarative transaction. I can just annotate a method with @Transactional and spring will delegate properly to the underlying transaction manager. My code does not even need to be aware that it is inside of a transaction. I can specify rollback and propagation rules here to.

2. Easily testable.

 
Nitin Gaur
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vaibhav, So you want to know that the transaction strategy should be applied to which layer? Service or DAO.
If the question is correct then the answer is Services layer. Transactions handling should go in DAO layer only if Services layer does not exist. For more about transaction strategies, read http://www.infoq.com/minibooks/JTDS
To be precise, if using Spring then use Spring to manage transactions preferrably declaratively.

cheers
-Nitin Gaur
 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nitin and Bill Gorder for your inputs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic