Transactions Questions with Answers

15 practice questions on Transactions (Spring Boot & JPA) with answers and step-by-step solutions. Try 10 samples below, then practise all 15 free in the AptiNest app.

Sample questions

Question 1Easy

The "A" in ACID stands for:

  1. Aggregation
  2. Availability
  3. Atomicity
  4. Authentication

Answer: C. Atomicity

Explanation

Atomicity: all operations in a transaction succeed or none do.

Step-by-step solution

  1. ACID = Atomicity, Consistency, Isolation, Durability.
  2. Atomicity means all or nothing.

Why the other options are wrong

  • A. Not part of ACID.
  • B. Availability belongs to CAP.
  • D. Not part of ACID.

Question 2Easy

Which annotation makes a method run inside a database transaction?

  1. @Transactional
  2. @Atomic
  3. @Database
  4. @Commit

Answer: A. @Transactional

Explanation

Spring wraps the method in a transaction via a proxy.

Step-by-step solution

  1. Spring transaction management uses annotations placed on methods or classes.
  2. @Transactional tells Spring to run the method inside a database transaction through a proxy.
  3. So the annotation is option A, @Transactional.

Why the other options are wrong

  • B. @Atomic is not a Spring transaction annotation.
  • C. @Database is not a Spring transaction annotation.
  • D. @Commit is a Spring Test annotation about committing in tests, not one that starts a transaction.

Tip: The Spring transaction annotation is @Transactional; place it on service methods.

Question 3Easy

If any step inside a @Transactional method fails with a RuntimeException, the database changes made in that method are:

  1. Committed partially
  2. Committed fully
  3. Rolled back
  4. Copied to a backup table

Answer: C. Rolled back

Explanation

A transaction is all-or-nothing.

Step-by-step solution

  1. @Transactional makes the method's database work all-or-nothing.
  2. A RuntimeException thrown inside the method marks the transaction for rollback.
  3. So all changes made in the method are rolled back, option C.

Why the other options are wrong

  • A. Partial commits do not happen inside one transaction.
  • B. A full commit would ignore the exception, which Spring does not do by default.
  • D. Spring does not copy changes to a backup table.

Tip: An unchecked exception in a @Transactional method rolls back all the database changes made in it.

Question 4Medium

Where is @Transactional usually best placed in a layered application?

  1. On DTO classes
  2. On service methods
  3. On JPA entity classes
  4. On the main class only

Answer: B. On service methods

Explanation

Services define business units of work that may span several repository calls.

Step-by-step solution

  1. A service method is a unit of business work.
  2. It may call several repositories that must all succeed or all fail together.
  3. So @Transactional belongs on service methods, option B.

Why the other options are wrong

  • A. DTOs only carry data and do not run business work.
  • C. Entities map data; the transaction belongs to the service that uses them.
  • D. Placing it only on the main class does not wrap each service method.

Tip: Put @Transactional on the service layer, not on DTOs or entities.

Question 5Medium

@Transactional(readOnly = true) is mainly a:

  1. Hint for optimisation of read-only work
  2. Security feature
  3. Way to make tables read-only
  4. Lock preventing other users from writing

Answer: A. Hint for optimisation of read-only work

Explanation

It can let Hibernate skip dirty checking and allow drivers or databases to optimise.

Step-by-step solution

  1. readOnly = true tells Spring and the driver that the method only reads data.
  2. That lets Hibernate skip some work such as dirty checking, and lets the driver optimise.
  3. So it is an optimisation hint, option A.

Why the other options are wrong

  • B. It is not a security feature; access control is separate.
  • C. It does not turn the tables read-only.
  • D. It does not lock other users out from writing.

Tip: readOnly = true is a hint for read methods; it is not an access control.

Question 6Medium

Propagation.REQUIRES_NEW means:

  1. Always use a new transaction
  2. Join the current transaction
  3. Fail if a transaction exists
  4. Run without any transaction

Answer: A. Always use a new transaction

Explanation

Useful for audit logs that must commit even if the outer transaction rolls back.

Step-by-step solution

  1. REQUIRES_NEW suspends any transaction that is already running.
  2. It always starts a brand new transaction for the method.
  3. So the meaning is option A, always use a new transaction.

Why the other options are wrong

  • B. Joining the current transaction is REQUIRED, not REQUIRES_NEW.
  • C. Failing when a transaction exists describes NEVER, not REQUIRES_NEW.
  • D. REQUIRES_NEW does not run without a transaction; it always starts one.

Tip: REQUIRES_NEW means a fresh transaction, with the outer one suspended until it finishes.

Question 7Medium

Do you need @EnableTransactionManagement in a typical Spring Boot application using JPA?

  1. Only on Windows
  2. No, Boot auto-configures it
  3. Yes, always
  4. Only for read-only methods

Answer: B. No, Boot auto-configures it

Explanation

Transaction management is enabled by auto-configuration when a transaction manager is present.

Step-by-step solution

  1. Spring Boot detects JPA and a transaction manager on the classpath.
  2. It configures transaction management automatically.
  3. So you do not need @EnableTransactionManagement in a typical app; the answer is option B.

Why the other options are wrong

  • A. Transaction management does not depend on the operating system.
  • C. In a typical Boot app you do not need to add it by hand.
  • D. It is not only needed for read-only methods.

Tip: Boot auto-configures transactions; add @EnableTransactionManagement only for custom setups.

Question 8Medium

What is the default propagation of @Transactional?

  1. NEVER
  2. NESTED
  3. REQUIRES_NEW
  4. REQUIRED

Answer: D. REQUIRED

Explanation

REQUIRED joins an existing transaction or starts a new one.

Step-by-step solution

  1. Propagation controls whether a method joins an existing transaction or starts a new one.
  2. The default, REQUIRED, joins an existing transaction if there is one.
  3. If there is none, it starts a new one, so the default is option D, REQUIRED.

Why the other options are wrong

  • A. NEVER is not the default; it fails if a transaction already exists.
  • B. NESTED is not the default propagation.
  • C. REQUIRES_NEW always starts a new transaction; it is not the default.

Tip: The default is REQUIRED; choose REQUIRES_NEW only when the work must commit independently.

Question 9Hard

What does @Transactional(isolation = Isolation.DEFAULT) mean?

  1. Use READ_UNCOMMITTED
  2. Use SERIALIZABLE
  3. Disable isolation
  4. The DB's default

Answer: D. The DB's default

Explanation

DEFAULT delegates to the underlying data store's default.

Step-by-step solution

  1. Isolation.DEFAULT does not pick a specific isolation level.
  2. It tells Spring to use the isolation level that the database uses by default.
  3. So the meaning is option D, the DB's default.

Why the other options are wrong

  • A. READ_UNCOMMITTED is a specific level that DEFAULT does not choose.
  • B. SERIALIZABLE is a specific strict level that DEFAULT does not choose.
  • C. Isolation is not disabled; the database default applies.

Tip: Set an explicit isolation level only when the database default does not give the guarantees you need.

Question 10Hard

An outer @Transactional method calls another bean's method annotated REQUIRED, which throws a RuntimeException that the outer method catches. What happens when the outer method tries to commit?

  1. Only the inner changes are rolled back
  2. The exception is ignored silently
  3. The outer transaction commits normally
  4. UnexpectedRollbackException

Answer: D. UnexpectedRollbackException

Explanation

Both methods share one transaction; the inner failure marks it rollback-only, so the outer commit fails.

Step-by-step solution

  1. Both methods share one transaction, because the inner method joins the outer one (REQUIRED).
  2. The inner RuntimeException marks the shared transaction as rollback-only, even though the outer method caught it.
  3. When the outer method tries to commit, Spring refuses and throws UnexpectedRollbackException, option D.

Why the other options are wrong

  • A. There is no partial rollback; the one shared transaction is marked for rollback as a whole.
  • B. The exception is not ignored; it still marks the shared transaction.
  • C. The outer commit cannot succeed because the transaction is already marked rollback-only.

Tip: A catch inside a joined transaction does not clear the rollback-only mark; use REQUIRES_NEW for work that must stand alone.

Practise all 15 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Spring Boot & JPA topics · All topics