The Spring @Transactional annotation declares that method or class execution participates in transaction management. It defines boundaries and execution rules for atomic database operations. section 11.4.3 section 20.5
Configure transaction behavior with these properties:
- isolation selects an ANSI isolation level, while propagation controls how existing transactions are handled. section 11.4.3
- timeout specifies seconds before automatic rollback, and readOnly identifies read-only work that may allow optimizations. section 11.4.3
- rollbackFor and rollbackForClassName add exception types that cause rollback; noRollbackFor and noRollbackForClassName exclude exception types. section 11.4.2
Apply the annotation to an interface, class, or method. Class- and interface-level declarations are inherited by their methods, while method annotations can override broader behavior. Method-level annotations on concrete classes provide the finest control. section 11.4.3
Transactional DAO
@Repository @Transactional public class ItemDaoImpl implements ItemDao { @PersistenceContext(type = PersistenceContextType.EXTENDED) private EntityManager em; public void insert(Item item) { em.persist(item); } public Item getById(long id) { return em.find(Item.class, id); } } Enable annotation-driven transaction management with @EnableTransactionManagement, or use the XML tx:annotation-driven element, and provide a transaction manager bean. section 14.2
For tests, placing @Transactional on the test class makes transactions active during each test method and its per-test setup and teardown, while they are inactive in suite-wide setup and teardown. Test transactions roll back by default; @Commit or @Rollback(false) changes that behavior. section 20.5
Table 11.4 @Transactional annotation properties (view table figure)
| Timeout after which the transaction will automatically roll back. |
||
| Declares if the transaction is read-only or read-write. Read-only transactions allow optimizations that can make them faster. |
Browse the annotation property table for isolation, propagation, timeout, and readOnly semantics. section 11.4.3

