Sample questions
Question 1Easy
The "A" in ACID stands for:
- Aggregation
- Availability
- Atomicity
- Authentication
Answer: C. Atomicity
Explanation
Atomicity: all operations in a transaction succeed or none do.
Step-by-step solution
- ACID = Atomicity, Consistency, Isolation, Durability.
- 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?
- @Transactional
- @Atomic
- @Database
- @Commit
Answer: A. @Transactional
Explanation
Spring wraps the method in a transaction via a proxy.
Step-by-step solution
- Spring transaction management uses annotations placed on methods or classes.
- @Transactional tells Spring to run the method inside a database transaction through a proxy.
- 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:
- Committed partially
- Committed fully
- Rolled back
- Copied to a backup table
Answer: C. Rolled back
Explanation
A transaction is all-or-nothing.
Step-by-step solution
- @Transactional makes the method's database work all-or-nothing.
- A RuntimeException thrown inside the method marks the transaction for rollback.
- 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?
- On DTO classes
- On service methods
- On JPA entity classes
- 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
- A service method is a unit of business work.
- It may call several repositories that must all succeed or all fail together.
- 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:
- Hint for optimisation of read-only work
- Security feature
- Way to make tables read-only
- 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
- readOnly = true tells Spring and the driver that the method only reads data.
- That lets Hibernate skip some work such as dirty checking, and lets the driver optimise.
- 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:
- Always use a new transaction
- Join the current transaction
- Fail if a transaction exists
- 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
- REQUIRES_NEW suspends any transaction that is already running.
- It always starts a brand new transaction for the method.
- 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?
- Only on Windows
- No, Boot auto-configures it
- Yes, always
- 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
- Spring Boot detects JPA and a transaction manager on the classpath.
- It configures transaction management automatically.
- 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?
- NEVER
- NESTED
- REQUIRES_NEW
- REQUIRED
Answer: D. REQUIRED
Explanation
REQUIRED joins an existing transaction or starts a new one.
Step-by-step solution
- Propagation controls whether a method joins an existing transaction or starts a new one.
- The default, REQUIRED, joins an existing transaction if there is one.
- 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?
- Use READ_UNCOMMITTED
- Use SERIALIZABLE
- Disable isolation
- The DB's default
Answer: D. The DB's default
Explanation
DEFAULT delegates to the underlying data store's default.
Step-by-step solution
- Isolation.DEFAULT does not pick a specific isolation level.
- It tells Spring to use the isolation level that the database uses by default.
- 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?
- Only the inner changes are rolled back
- The exception is ignored silently
- The outer transaction commits normally
- 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
- Both methods share one transaction, because the inner method joins the outer one (REQUIRED).
- The inner RuntimeException marks the shared transaction as rollback-only, even though the outer method caught it.
- 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 →