Complete the code to enable transaction management on the service method.
@Service public class UserService { @[1] public void createUser(User user) { // method implementation } }
The @Transactional annotation marks the method to run within a transaction.
Complete the code to specify that the transaction should roll back on any exception.
@Transactional(rollbackFor = [1].class) public void updateUser(User user) { // update logic }
Using rollbackFor = Exception.class ensures rollback on checked and unchecked exceptions.
Fix the error in the annotation to make the transaction read-only.
@Transactional(readOnly = [1])
public List<User> getUsers() {
// fetch users
}The readOnly attribute expects a boolean value true or false, not a string.
Fill both blanks to configure a transaction with propagation REQUIRED and isolation level SERIALIZABLE.
@Transactional(propagation = Propagation.[1], isolation = Isolation.[2]) public void processOrder(Order order) { // processing logic }
Propagation.REQUIRED means join existing or create new transaction.Isolation.SERIALIZABLE is the strictest isolation level.
Fill all three blanks to create a transaction that is read-only, with timeout 30 seconds, and rollback on IllegalArgumentException.
@Transactional(readOnly = [1], timeout = [2], rollbackFor = [3].class) public void validateData(Data data) { // validation logic }
Setting readOnly=true optimizes for read operations.
Timeout limits transaction duration.
Rollback on IllegalArgumentException handles specific errors.