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?
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.
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.
If you don't like something, change it. If you can't change it, change your attitude. Don't complain.
Vaibhav G Garg
Joined: Sep 23, 2011
Thanks Nitin and Bill Gorder for your inputs.
subject: Transaction related question in Spring Hibernate Application