Senior
Name the parameters of the @Transactional annotation.
sobes.tech AI
Answer from AI
The @Transactional annotation in Spring is used for transaction management and has several key parameters:
propagation— defines the behavior of the transaction when calling a method, such asREQUIRED,REQUIRES_NEW,SUPPORTS, etc.isolation— the isolation level of the transaction, for example,READ_COMMITTED,SERIALIZABLE.timeout— the maximum execution time of the transaction in seconds.readOnly— indicates that the transaction is read-only, which can optimize database operations.rollbackForandnoRollbackFor— exception classes for which the transaction should or should not be rolled back.
Example of usage:
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 30, readOnly = false, rollbackFor = Exception.class)
public void updateData() {
// business logic
}