Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between using @Transactional and Spring template?

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?

like image 705
cometta Avatar asked May 18 '09 10:05

cometta


1 Answers

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.

like image 70
Paul Morie Avatar answered Oct 17 '22 08:10

Paul Morie