File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Transaction related question in Spring Hibernate Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Transaction related question in Spring Hibernate Application" Watch "Transaction related question in Spring Hibernate Application" New topic
Author

Transaction related question in Spring Hibernate Application

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
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

Joined: Mar 07, 2010
Posts: 1648
    
    7

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.


[How To Ask Questions][Read before you PM me]
Nitin Gaur
Greenhorn

Joined: Sep 06, 2003
Posts: 27
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


If you don't like something, change it. If you can't change it, change your attitude. Don't complain.
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thanks Nitin and Bill Gorder for your inputs.
 
 
subject: Transaction related question in Spring Hibernate Application