0
0
Spring Bootframework~10 mins

Transaction management with @Transactional in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable transaction management on the service method.

Spring Boot
@Service
public class UserService {
    @[1]
    public void createUser(User user) {
        // method implementation
    }
}
Drag options to blanks, or click blank then click option'
AService
BAutowired
CComponent
DTransactional
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Autowired instead of @Transactional
Forgetting to add @Transactional on methods that modify data
2fill in blank
medium

Complete the code to specify that the transaction should roll back on any exception.

Spring Boot
@Transactional(rollbackFor = [1].class)
public void updateUser(User user) {
    // update logic
}
Drag options to blanks, or click blank then click option'
ARuntimeException
BThrowable
CException
DError
Attempts:
3 left
💡 Hint
Common Mistakes
Using RuntimeException only rolls back unchecked exceptions
Using Error is not recommended for rollback
3fill in blank
hard

Fix the error in the annotation to make the transaction read-only.

Spring Boot
@Transactional(readOnly = [1])
public List<User> getUsers() {
    // fetch users
}
Drag options to blanks, or click blank then click option'
Atrue
BTrue
C"true"
DTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around true makes it a string, causing errors
Using uppercase True or TRUE is invalid in Java
4fill in blank
hard

Fill both blanks to configure a transaction with propagation REQUIRED and isolation level SERIALIZABLE.

Spring Boot
@Transactional(propagation = Propagation.[1], isolation = Isolation.[2])
public void processOrder(Order order) {
    // processing logic
}
Drag options to blanks, or click blank then click option'
AREQUIRED
BREQUIRES_NEW
CSERIALIZABLE
DREAD_COMMITTED
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing propagation types
Using lower isolation levels when strict consistency is needed
5fill in blank
hard

Fill all three blanks to create a transaction that is read-only, with timeout 30 seconds, and rollback on IllegalArgumentException.

Spring Boot
@Transactional(readOnly = [1], timeout = [2], rollbackFor = [3].class)
public void validateData(Data data) {
    // validation logic
}
Drag options to blanks, or click blank then click option'
Afalse
B30
CIllegalArgumentException
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting readOnly to false when method only reads data
Forgetting to specify rollbackFor for checked exceptions