Challenge - 5 Problems
Read-only Transaction Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a read-only transaction tries to perform a write?
Consider a Spring Boot service method annotated with
@Transactional(readOnly = true). What is the expected behavior if this method attempts to save a new entity to the database?Spring Boot
import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service public class UserService { @Transactional(readOnly = true) public void createUser(String name) { User user = new User(); user.setName(name); userRepository.save(user); // Attempt to write inside read-only transaction } }
Attempts:
2 left
💡 Hint
Think about how Spring enforces read-only transactions at runtime.
✗ Incorrect
Spring marks the transaction as read-only, and depending on the database and transaction manager, attempting to write inside such a transaction typically causes an exception to prevent data modification.
📝 Syntax
intermediate1:30remaining
Identify the correct way to declare a read-only transaction in Spring Boot
Which of the following method annotations correctly configures a read-only transaction in Spring Boot?
Attempts:
2 left
💡 Hint
Pay attention to case sensitivity and annotation spelling.
✗ Incorrect
The correct attribute name is 'readOnly' with capital 'O' and the annotation is '@Transactional'.
❓ state_output
advanced2:00remaining
What is the effect of read-only transactions on Hibernate's session flush?
In a Spring Boot application using Hibernate, what happens to the session flush behavior inside a method annotated with
@Transactional(readOnly = true)?Attempts:
2 left
💡 Hint
Think about how read-only transactions optimize performance by avoiding unnecessary writes.
✗ Incorrect
In read-only transactions, Hibernate avoids flushing the session to prevent accidental data changes, improving performance.
🔧 Debug
advanced2:30remaining
Why does a read-only transaction still allow data modification in some cases?
A developer marks a service method with
@Transactional(readOnly = true) but notices that data is still being updated in the database. What is the most likely cause?Attempts:
2 left
💡 Hint
Consider how different databases handle read-only flags.
✗ Incorrect
Some databases or transaction managers do not enforce read-only transactions, so writes can still occur despite the annotation.
🧠 Conceptual
expert3:00remaining
Why use read-only transactions in Spring Boot applications?
Which of the following is the best explanation for why developers use
@Transactional(readOnly = true) in Spring Boot service methods?Attempts:
2 left
💡 Hint
Think about how read-only transactions affect database interaction and resource usage.
✗ Incorrect
Read-only transactions help optimize performance by signaling the database and ORM to avoid unnecessary locking and flushing, improving efficiency for read operations.