I have been googling for several hour now trying to find an example on how to write a service method that doesn’t use Springs Hibernate Template while using a DAO interface. Something that is also confusing me is what happens when I put the @Transactional annotation in the service layer as opposed the DAO. Are the Service methods/DAO interfaces interchangeable?
Here is an example where the @Transactional is in the DAO
Here is one with the @Transactional in the Service Layer but using hibernate templates
Thanks for your help!
The Spring documentation recommends avoiding HibernateTemplate completely, and use the Hibernate API directly instead:
And the
@Transactionalannotation should always be put on methods of the service layer. This is the layer that demarcates transactions.Read http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#orm-session-factory-setup to understand how to setup a session factory. Once done, the session factory can be injected in your DAOs: