Spring Boot interview questions: @Transactional and transaction management
Reviewed by Mark Dickie · Last updated
5 questions on this page you can answer and see marked on the spot. Go to the first one
Transactions in Spring Boot are units of work declared with the @Transactional annotation and run by a PlatformTransactionManager bean. Interviewers usually probe three things: how the proxy decides when to roll back, why a call from inside the same class skips the transaction, and what the propagation levels REQUIRED and REQUIRES_NEW change. The default rollback rule trips up many candidates, since unchecked exceptions and Errors roll back while checked exceptions commit unless rollbackFor says otherwise. Know those three points and most service-layer and Spring Data questions become straightforward.
What do the @Transactional settings change?
| Setting | Default | What it changes |
|---|---|---|
| propagation | REQUIRED | Joins the caller's transaction, or starts one if none exists. |
| propagation | REQUIRES_NEW | Suspends the outer transaction and commits or rolls back on its own. |
| propagation | NESTED | Creates a savepoint inside the outer transaction; needs JDBC savepoint support. |
| rollbackFor | none (unchecked only) | Forces rollback on checked exceptions such as IOException. |
| readOnly | false | Passes a hint to the driver and Hibernate flush mode; it does not block every write. |
| isolation | DEFAULT | Sets the isolation level of the database for the new transaction. |
Which Spring Boot transaction mistakes come up in interviews?
- Call a @Transactional method from another method in the same class, then check the logs to confirm no transaction started, because the call bypasses the proxy.
- Throw a checked exception from a @Transactional method and check whether the saved rows persist.
- Put @Transactional on a private method and observe that the default proxy setup ignores it.
- Nest a REQUIRES_NEW method inside a REQUIRED method, force a failure in the outer call, and track which inserts survive.
- Hand work to @Async or a new thread from inside a @Transactional method, and note that the new thread runs outside the transaction.
Key facts
- Tarmac has 12 Spring Boot interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
- Tarmac tracked 410 job postings asking for Spring Boot in November 2026.
- Roles asking for Spring Boot advertise a median base salary of £75,000, across 155 job postings as of November 2026.
- Tarmac last reviewed these Spring Boot interview questions on 30 November 2026.
At a glance
| Questions | 10 shown · 12 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | Multiple choice, Ordering, Multiple answer, Code output, True / false, Find the bug, Short answer, Fill in the blank, Flashcard |
What you'll review
- transactions and transactional
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
In a Spring Boot application, a public service method is annotated with @Transactional with default settings. By default, which kind of exception thrown from the method causes the transaction to be rolled back?#
Options
Show answer
Spring's @Transactional rolls back by default only on unchecked exceptions, meaning RuntimeException and its subclasses, and on Error. Checked exceptions do not trigger rollback, so the transaction commits unless you configure rollbackFor, for example @Transactional(rollbackFor = Exception.class).
Spring's default rollback rule for @Transactional is to roll back on unchecked exceptions, meaning RuntimeException and its subclasses, and on Error. Checked exceptions do not trigger rollback by default, and the transaction still commits. So the choices saying only checked exceptions or any Throwable cause rollback are wrong. Rollback is also not opt-in only, so the choice saying it must always be set explicitly is wrong too. To roll back on checked exceptions, use rollbackFor, for example @Transactional(rollbackFor = Exception.class).
A Spring Boot bean has a public method annotated with @Transactional (default settings). Another bean calls it, no transaction is already active, and the method finishes without throwing. Put these events in the order they happen.#
Put these in order
Show answer
A Spring @Transactional call goes in this order: the caller hits the proxy, the proxy starts a transaction, the real method body runs, the proxy commits, and then the result goes back to the caller. The proxy wraps the method call, so the transaction starts before your code runs and commits after it returns normally.
@Transactional works through a proxy that wraps the bean. The call reaches the proxy first. Because the default propagation is REQUIRED and no transaction is active yet, the proxy opens a new one. Next it hands the call to the real method, so all the repository work runs inside that transaction. When the method returns without an exception, the proxy commits. Only after the commit does the caller get the return value.
In Spring (as used by Spring Boot 3), what is the default propagation setting of @Transactional when none is specified?#
Options
Show answer
Spring's @Transactional defaults to Propagation.REQUIRED. The annotated method joins a transaction that is already in progress. If no transaction exists, Spring starts a new one. Other behaviours have to be chosen explicitly: REQUIRES_NEW for an independent transaction, SUPPORTS for running with or without a transaction, and NESTED for savepoints.
@Transactional defaults to Propagation.REQUIRED. With this setting the method joins a transaction that is already active, and it starts a new transaction only when none exists. REQUIRES_NEW always suspends the current transaction and starts a fresh one. SUPPORTS runs without a transaction if none is active. NESTED uses a savepoint inside the existing transaction. None of those three is the default.
In a Spring Boot application using Spring's default proxy-based @Transactional support (no AspectJ weaving, default rollback rules), which of the following statements are true? Select all that apply.#
Options
Pick every one that applies.
Show answer
Spring's @Transactional rolls back by default only on unchecked exceptions (RuntimeException, Error). Checked exceptions commit unless you set rollbackFor, such as rollbackFor = Exception.class. With proxy-based AOP, self-invocation through this skips the proxy, so no transactional behavior is applied to that call. The default propagation is REQUIRED, not REQUIRES_NEW.
Spring's default rollback rules roll back only on unchecked exceptions (RuntimeException and Error); checked exceptions commit unless configured otherwise, which is exactly what rollbackFor = Exception.class changes. Because proxy-based AOP intercepts only calls arriving through the proxy, a self-invocation via this skips the transactional advice. The default propagation is REQUIRED (join an existing transaction or create one), not REQUIRES_NEW, so that statement and the checked-exception rollback statement are false.
Spring Boot 3 with Spring Data JPA, default proxy-based @Transactional, and an empty orders table at startup. What does the runner print?#
@Service
public class OrderService {
@Autowired OrderRepository repo; // extends JpaRepository<Order, Long>
public void placeOrder() {
try {
this.saveAndFail();
} catch (RuntimeException e) {
// swallowed
}
}
@Transactional
public void saveAndFail() {
repo.save(new Order());
throw new IllegalStateException("boom");
}
}
@Component
class Runner implements CommandLineRunner {
@Autowired OrderService service;
@Autowired OrderRepository repo;
public void run(String... args) {
service.placeOrder();
System.out.println(repo.count());
}
}Show answer
1
placeOrder() has no @Transactional, and it calls saveAndFail() through this. That call goes straight to the target object and never passes through the Spring proxy, so the @Transactional on saveAndFail() does nothing and no transaction is started. The insert therefore runs only inside the transaction that Spring Data's SimpleJpaRepository.save opens for itself, and that transaction commits as soon as save returns. The IllegalStateException is thrown after the commit, so there is nothing left to roll back, and the caller swallows it. The row stays in the table and count() prints 1.
In a Spring Boot application using the default proxy-based @Transactional support, a public method placeOrder() with no @Transactional annotation calls this.saveOrder(). saveOrder() is a public method in the same bean, annotated with @Transactional(propagation = Propagation.REQUIRES_NEW). True or false: this call starts a new transaction for saveOrder().#
Options
Show answer
A self-invoked @Transactional method does not start a new transaction under Spring's default proxy-based AOP. Calling this.saveOrder() skips the transactional proxy, so REQUIRES_NEW is ignored. To make it work, move the method into another Spring bean, call it through an injected proxy, use TransactionTemplate, or enable AspectJ mode.
By default, Spring applies @Transactional through a proxy (JDK dynamic proxy or CGLIB) that wraps the bean. The transaction interceptor only runs when a call goes through that proxy. this.saveOrder() is a self-invocation: it calls the target object directly and never passes through the proxy. So the REQUIRES_NEW setting is ignored and no new transaction starts. Common fixes are to move the method into a separate bean, inject the bean's own proxy (self-injection), use TransactionTemplate, or switch to AspectJ weaving mode.
Spring Boot 3 with the default proxy-based @Transactional support and JPA. The requirement: an audit entry must always be committed, even when the payment fails and its transaction rolls back. In testing, failed payments leave no audit row. AuditService and PaymentService are separate beans. Which line has the bug?#
@Service
public class AuditService {
private final AuditRepository auditRepository;
public AuditService(AuditRepository auditRepository) {
this.auditRepository = auditRepository;
}
@Transactional(propagation = Propagation.REQUIRED)
public void record(String action) {
auditRepository.save(new AuditEntry(action));
}
}
@Service
public class PaymentService {
private final AuditService auditService;
private final PaymentRepository paymentRepository;
public PaymentService(AuditService a, PaymentRepository p) {
this.auditService = a;
this.paymentRepository = p;
}
@Transactional
public void pay(Payment payment) {
auditService.record("PAY_ATTEMPT " + payment.getId());
paymentRepository.save(payment);
if (payment.getAmount().signum() <= 0) {
throw new IllegalArgumentException("invalid amount");
}
}
}Show answer
The bug is on line 7.
Line 7 is the bug. record() is called on a separate bean, so it does go through the proxy, and the transaction advice runs. But Propagation.REQUIRED joins the transaction that pay() already has open, so the audit insert becomes part of the payment transaction. When pay() throws the unchecked IllegalArgumentException, the whole shared transaction rolls back, and the audit row is lost with it. Changing line 7 to Propagation.REQUIRES_NEW fixes it. That setting suspends the outer transaction and runs record() in its own physical transaction, which commits when record() returns, before the payment can fail. The rest of the code is correct: constructor injection works, a cross-bean call is not a self-invocation, and a runtime exception does trigger a rollback by default.
In a Spring Boot 3 service using default proxy-based @Transactional (no AspectJ weaving), OrderService.placeOrder() is annotated @Transactional and calls auditService.log() (a different bean) annotated @Transactional(propagation = Propagation.REQUIRED). log() throws a RuntimeException, and placeOrder() catches it and returns normally. What happens at commit time, and why? How would you change the design so a failed audit log does not doom the order, and what is the trade-off?#
Show answer
Because log() uses REQUIRED it joins the outer transaction. When the RuntimeException passes through the inner transactional proxy, the interceptor marks the shared transaction rollback-only. placeOrder() swallowing the exception doesn't clear that flag, so when the outer proxy tries to commit, Spring finds the rollback-only mark, rolls everything back, and throws UnexpectedRollbackException. The order is not saved. Fix: annotate log() with Propagation.REQUIRES_NEW. The outer transaction is suspended and the audit runs in its own physical transaction (and its own connection), so its rollback doesn't affect the order. Another option is noRollbackFor on the inner method. Trade-offs: REQUIRES_NEW takes a second pooled connection, which can exhaust the pool or deadlock under load. The audit also commits on its own, so it can't see the outer transaction's uncommitted rows and stays committed even if the order later rolls back.
With REQUIRED propagation, both methods share one physical transaction. When an unchecked exception passes through the inner proxy, that proxy marks the whole transaction rollback-only. Catching the exception later doesn't undo the mark, so the outer commit turns into a rollback and Spring throws UnexpectedRollbackException. With REQUIRES_NEW, the outer transaction is suspended and the audit runs in its own transaction, so an audit failure no longer rolls back the order. The cost is a second database connection and independent commit and visibility semantics.
In Spring Boot with default proxy-based @Transactional, OrderService.place() (default propagation) calls auditService.log() on another bean. log() is also @Transactional with default propagation REQUIRED. log() throws a RuntimeException, and place() catches it and returns normally. When the transaction manager tries to commit, it throws _____, because the inner method marked the shared physical transaction rollback-only. To let log() fail without affecting the outer transaction, annotate it with @Transactional(propagation = Propagation._____). That suspends the outer transaction and runs log() in its own independent physical transaction.#
Show answer
In Spring Boot with default proxy-based @Transactional, OrderService.place() (default propagation) calls auditService.log() on another bean. log() is also @Transactional with default propagation REQUIRED. log() throws a RuntimeException, and place() catches it and returns normally. When the transaction manager tries to commit, it throws **UnexpectedRollbackException**, because the inner method marked the shared physical transaction rollback-only. To let log() fail without affecting the outer transaction, annotate it with @Transactional(propagation = Propagation.**REQUIRES_NEW**). That suspends the outer transaction and runs log() in its own independent physical transaction.
With REQUIRED, the inner method joins the outer physical transaction, so both methods share one transaction. When a RuntimeException leaves the inner proxy, the interceptor marks that shared transaction rollback-only, even though the outer code catches the exception. When the outer method then commits, the manager sees the rollback-only flag, rolls back, and throws UnexpectedRollbackException so the caller isn't misled into thinking the commit worked. REQUIRES_NEW suspends the outer transaction and opens a separate physical transaction for the inner call. A rollback there doesn't mark the outer transaction, so after catching the exception the outer transaction can still commit. (NESTED uses savepoints and is driver-dependent, and it isn't supported with JPA's transaction manager, so the wording asks for an independent physical transaction.)
In Spring Framework 6 / Spring Boot 3, a method marked @Transactional(propagation = REQUIRES_NEW) runs inside an outer @Transactional (REQUIRED) method. It uses a JDBC DataSource via DataSourceTransactionManager or JPA. What happens at the resource level when the inner method starts and ends, and what production failure mode can this cause under load?#
Show answer
When the inner method starts, AbstractPlatformTransactionManager suspends the outer transaction. It unbinds the outer ConnectionHolder/EntityManagerHolder and any synchronizations from TransactionSynchronizationManager's ThreadLocals. Then it takes a second physical connection from the pool and starts a new transaction on it. When the inner method ends, that connection is committed or rolled back and released, and the outer resources are bound back to the thread. The outer connection stays checked out the whole time, so each thread holds two connections at once.
Failure mode: pool-exhaustion deadlock. Suppose the pool has N connections and N or more threads have each taken their outer connection. All of them then block waiting for a second connection that never frees up, and each wait ends only at the pool timeout (HikariCP's connectionTimeout). A related risk: the inner transaction may wait on row locks still held by the suspended outer transaction on the same thread. That is a self-deadlock the database cannot detect, because the two connections are separate sessions.
Fixes: size the pool to at least threads × (nesting depth + 1), avoid REQUIRES_NEW on hot paths, or use NESTED (JDBC savepoints on the same connection, supported by DataSourceTransactionManager).
With REQUIRES_NEW, Spring suspends the outer transaction and opens a new physical transaction on a separate connection. One thread therefore holds two pooled connections at the same time. Under concurrency, that can starve the pool until every thread is stuck waiting for a second connection. It can also block a thread on row locks held by its own suspended outer transaction. These details are what a staff-level answer should cover.
Related interview questions
Job market
See spring-boot salaries and hiring demand from live job postings.
The other 2 questions
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 2 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback