Recall & Review
beginner
What is a read-only transaction in Spring Boot?
A read-only transaction is a transaction that only reads data and does not modify it. It tells the database and Spring that no data changes will happen, which can improve performance and safety.
Click to reveal answer
beginner
How do you declare a read-only transaction in Spring Boot?
You use the @Transactional annotation with the attribute readOnly=true, like this: <br>
@Transactional(readOnly = true) on a method or class.Click to reveal answer
intermediate
Why use read-only transactions?
Read-only transactions can make your app faster by avoiding unnecessary locks and checks in the database. They also help prevent accidental data changes during read operations.
Click to reveal answer
intermediate
What happens if you try to write data inside a read-only transaction?
Depending on the database and configuration, it may throw an error or ignore the write. Spring tries to optimize for reads, so writes inside a read-only transaction are discouraged and can cause unexpected behavior.
Click to reveal answer
intermediate
Can read-only transactions improve database concurrency?
Yes, because they reduce locking and resource use, allowing more read operations to happen at the same time without blocking each other.
Click to reveal answer
How do you mark a method as read-only in Spring Boot?
✗ Incorrect
The correct way is to use @Transactional with readOnly = true.
What is a benefit of using read-only transactions?
✗ Incorrect
Read-only transactions reduce locking and improve performance for read operations.
What might happen if you write data inside a read-only transaction?
✗ Incorrect
Writing inside a read-only transaction can cause errors or unexpected behavior.
Which annotation attribute controls read-only behavior in Spring transactions?
✗ Incorrect
The attribute is named readOnly with camel case.
Read-only transactions are best used for:
✗ Incorrect
They are designed for operations that only read data.
Explain what a read-only transaction is and why it is useful in Spring Boot.
Think about how telling the system you won't change data can help.
You got /3 concepts.
Describe how to declare a read-only transaction in Spring Boot and what happens if you try to write data inside it.
Focus on the annotation and consequences of writing inside.
You got /3 concepts.