Issue
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?
Solution
The difference between using annotation-based transaction demarcation (@Transactional
) and the TransactionTemplate
is that TransactionTemplate
couples you to Spring's transaction infrastructure and means that you will programmatically handle setting the transaction status if the transaction should be rolled back. You can use annotation-based transaction demarcation with the Spring transaction support or with AspectJ transactions outside of a Spring container.
See also the online documentation for transactions in Spring.
Answered By - Paul Morie
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)