@Transactional Annotation Parameters Explained
1. value/transactionManager
Specifies the transaction manager, both are aliases for each other.
2. propagation (Transaction Propagation)
- REQUIRED: Default option, joins existing transaction or creates new transaction
- REQUIRES_NEW: Always creates new transaction, suspends existing transaction
- SUPPORTS: Supports current transaction, can also execute without transaction
- NOT_SUPPORTED: Executes in non-transactional manner
- MANDATORY: Must run within existing transaction
- NEVER: Cannot run within transaction
- NESTED: Nested within existing transaction, can set savepoint for partial rollback
3. isolation (Isolation Level)
- DEFAULT: Uses database default level
- READ_UNCOMMITTED: Lowest level, dirty reads may occur
- READ_COMMITTED: Solves dirty reads, non-repeatable reads and phantom reads may occur
- REPEATABLE_READ: Solves non-repeatable reads, MySQL default level
- SERIALIZABLE: Highest level, solves all concurrency problems, lowest performance
4. timeout
Sets transaction timeout time (seconds), automatically rolls back on timeout.
5. readOnly
Sets read-only transaction, used for query operations to optimize performance.
6. rollbackFor/rollbackForClassName
Specifies exception types that trigger rollback. By default, RuntimeException and Error will roll back.
7. noRollbackFor/noRollbackForClassName
Specifies exception types that do not trigger rollback, opposite of rollbackFor.
Summary
Understanding core concepts and practical application techniques of Spring transaction management is essential for developing reliable data processing flows.