Quick revision
The short answer
By default @Transactional uses propagation REQUIRED, isolation DEFAULT (whatever the database uses), no timeout and readOnly false, and it rolls back on RuntimeException and Error but commits on checked exceptions. Since Spring Framework 6.0, public, protected and package-private methods are supported with class-based proxies, while private methods are never intercepted. A class-level annotation applies to the methods of that class, a method-level one overrides it, and Spring also honours jakarta.transaction.Transactional.
What to remember
In this answer, we saw that @Transactional defaults to REQUIRED propagation, the database's own isolation level, no timeout and a read-write transaction, and that it rolls back only on RuntimeException and Error. Since Spring Framework 6.0, protected and package-private methods work with class-based proxies, but private and final methods are never intercepted. A method-level annotation replaces the class-level one, and Spring treats jakarta.transaction.Transactional the same way.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
By default @Transactional uses propagation REQUIRED, isolation DEFAULT (whatever the database uses), no timeout and readOnly false, and it rolls back on RuntimeException and Error but commits on checked exceptions. Since Spring Framework 6.0, public, protected and package-private methods are supported with class-based proxies, while private methods are never intercepted. A class-level annotation applies to the methods of that class, a method-level one overrides it, and Spring also honours jakarta.transaction.Transactional.
Why this question is asked
Most of us write @Transactional without any attributes, which means we are relying on every default it has. Those defaults decide whether our method joins another transaction, what data it can see, whether a checked exception leaves half-written data behind, and whether the annotation does anything at all. Interviewers ask this question because almost every transaction bug in Spring comes from one of these defaults being different from what the developer assumed. In this answer, we will go through each attribute and its default, see the rollback rules in code, look at which method visibilities work and why, and finish with how class-level and method-level annotations combine.
1A Quick Recap of What @Transactional Controls
A transaction is a unit of work against the database that either commits completely or rolls back completely. @Transactional asks Spring to start or join one around a method call. Its attributes answer five questions: should the method join an existing transaction (propagation), how isolated it is from other transactions running at the same time (isolation), how long it may run (timeout), whether it only reads (readOnly), and which exceptions undo the work (rollback rules).
| Attribute | Default | Meaning |
|---|---|---|
| propagation | REQUIRED | Join the current transaction, or start one if there is none |
| isolation | DEFAULT | Use the database's own level (READ COMMITTED on PostgreSQL) |
| timeout | -1 (TIMEOUT_DEFAULT) | No Spring timeout; the database or driver may have one |
readOnly | false | Normal read-write transaction |
rollbackFor | RuntimeException, Error | Checked exceptions commit unless listed |
2Propagation, Isolation, Timeout and readOnly
REQUIRED means that if the caller already has a transaction, our method takes part in it, and if not, Spring starts a new one. This is why two @Transactional methods calling each other usually share one transaction: the inner one joins the outer one.
Isolation DEFAULT means Spring does not set any level on the connection, so we get the database's default: READ COMMITTED on PostgreSQL, Oracle and SQL Server, REPEATABLE READ on MySQL InnoDB. The same code can therefore behave differently when a team moves between databases.
The timeout default of -1 means Spring sets no limit, so a slow transaction holds its connection and locks for as long as it takes. Spring Boot has a spring.transaction.default-timeout property if we want a global limit. readOnly false means Spring treats the transaction as one that may write; setting readOnly = true is a hint that lets Hibernate skip dirty checking and lets some drivers mark the connection read-only.
3The Rollback Rules in Code
The default rollback rule surprises many people. Spring follows the old EJB convention: an unchecked exception (RuntimeException or Error) means something went wrong, so it rolls back, while a checked exception is seen as a business outcome the caller may handle, so it commits.
Notice that nothing in the first method looks wrong, yet the two orders stay in the database after the failure. Adding rollbackFor = Exception.class, or wrapping the checked exception in an unchecked one, makes the method roll back on everything. Spring Framework 6.2 also added a way to change this default for the whole application through @EnableTransactionManagement; check your version for the exact attribute.
4Which Method Visibilities Work, and Why
Spring applies @Transactional through a proxy, a wrapper object that Spring generates at runtime and injects in place of our bean. The proxy can only add behaviour to methods it can override. With a class-based (CGLIB) proxy, which Spring Boot uses by default, the proxy is a subclass of our class.
Before Spring Framework 6.0, only public methods were treated as transactional. Since 6.0, protected and package-private methods are supported too when a class-based proxy is used, because a subclass in the same package can override them. Private methods can never be overridden, so the annotation on a private method is silently ignored. The same goes for final methods. With an interface-based JDK proxy, only methods declared on the interface, which are public, can be intercepted.
And whatever the visibility, the call must come through the proxy. A call from a() to b() inside the same object is a call on this and skips the proxy.
5Class-Level Versus Method-Level Annotations
When we put @Transactional on a class, it applies to the methods of that class (the public ones, plus protected and package-private ones under the 6.0 rule above). It does not apply to methods inherited from a superclass that are declared elsewhere. When a method has its own @Transactional, Spring uses the method's annotation instead of the class's; the two are not merged attribute by attribute.
This is how SimpleJpaRepository is written: the class has @Transactional(readOnly = true), and methods that write, such as save() and delete(), carry their own @Transactional, which overrides the read-only setting.
Spring also recognises jakarta.transaction.Transactional, the standard Jakarta EE annotation. It has its own attributes, such as value for the transaction type and rollbackOn instead of rollbackFor, and Spring maps them to the same behaviour, so code shared with a Jakarta EE application server can keep it.
6Follow-up questions
Does REQUIRED mean an inner method's failure only rolls back the inner work?
No. With REQUIRED the inner method joins the outer transaction, so there is only one physical transaction. If the inner method throws an exception that its proxy sees, the whole shared transaction is marked rollback-only, even if the outer method catches the exception.
Is readOnly = true enforced?
Not by Spring itself. It is a hint passed to the transaction manager, Hibernate and the JDBC driver. Hibernate stops flushing and dirty checking, and some drivers mark the connection read-only, which some databases enforce, but we should not treat it as a security control.
Where should the annotation go, on the interface or the class?
On the concrete class or its methods. Annotations on interfaces only work reliably with interface-based proxies, and since Spring Boot uses class-based proxies by default, putting it on the class is the safe and recommended choice.
7Conclusion
In this answer, we saw that @Transactional defaults to REQUIRED propagation, the database's own isolation level, no timeout and a read-write transaction, and that it rolls back only on RuntimeException and Error. Since Spring Framework 6.0, protected and package-private methods work with class-based proxies, but private and final methods are never intercepted. A method-level annotation replaces the class-level one, and Spring treats jakarta.transaction.Transactional the same way.
Open with
Without attributes, @Transactional means propagation REQUIRED, so it joins an existing transaction or starts one; isolation DEFAULT, which is whatever the database uses, so READ COMMITTED on PostgreSQL and REPEATABLE READ on MySQL; no timeout from Spring; and readOnly false.
Then, if they want more
The rollback rule is the one that catches people: it rolls back on RuntimeException and Error, but commits when a checked exception is thrown, so if I want rollback on something like IOException I add rollbackFor or wrap it. Spring 6.2 also offers a global setting for that, which I would check for the version in use.
On visibility, it works through a proxy, so only methods the proxy can override are intercepted. Since Spring Framework 6.0, with class-based proxies, which Spring Boot uses by default, protected and package-private methods work as well as public ones. Private and final methods are never transactional, and Spring ignores the annotation silently.
If I put it on the class, it applies to that class's methods, and an annotation on a method overrides the class one completely. Spring also supports jakarta.transaction.Transactional with the same proxy rules.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What are the default settings of @Transactional (propagation, isolation, timeout...": https://scrivio-interview-library.netlify.app/databases/transactions/64640afd72/