It's not a secret anymore!*
The moose likes Spring and the fly likes @Transaction annotation in dao or service layer ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@Transaction annotation in dao or service layer ?" Watch "@Transaction annotation in dao or service layer ?" New topic
Author

@Transaction annotation in dao or service layer ?

everson santos
Ranch Hand

Joined: Jul 11, 2009
Posts: 50


where is the best approach to put @Transaction annotation ? dao or service layer ?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Depends.

Personally, I make my services transactional, my DAOs not--that way I don't need to nest transactions inside a service if I use multiple DAO calls. Of course, I also make my services implement the same interface my DAOs do, which some people find very annoying and redundant :)
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Services and only when necessary.



This is a total waste of a transaction since no other db writes are being made.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @Transaction annotation in dao or service layer ?
 
Similar Threads
Spring Hibernate Transaction
Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction
Unable to catch the java.sql.BatchUpdateException (Spring)
Problem with @Transactional (Transaction is not getting rollbacked)
Spring 2.5 @Transactional not working