Spring – What’s the difference between using @Transactional and Spring template

springspring-mvc

If I use @Transactional in my DAO will all of my EntityManager queries be encapsulated with commit and close? Or do I need to use Spring template (JPA template, Hibernate template)? What's the difference between using @Transactional and Spring template?

Best Solution

The Spring template classes are only there to provide a nicer API for doing persistence operations - they do not deal with transactions. If you want to have transactional operations, you either need to use the @Transactional annotation approach, or use TransactionTemplate.