QuickDevGuide

Home › Spring Boot

Transactions — Spring Boot

@Transactional wraps a method in a database transaction via a proxy: commit on success, rollback on unchecked exceptions. Attribute Notes readOnly = true hint for read-only work (Hibernate skips dirty checking) rollbackFor = Exception.class also roll back on checked exceptions propagation = REQUIRED (default) join an existing transaction or start one propagation = REQUIRESNEW independent inner transaction (e.g. audit log that must persist) isolation READCOMMITTED, REPEATABLEREAD, SERIALIZABLE timeout seconds before rollback Proxy pitfalls Calling a @Transactional method from the same class bypasses the proxy — no transaction. Only public methods are intercepted (by default). Catching an exception inside the method prevents rollback unless you rethrow. Put transactions on service methods…

Key Takeaways