Sobes.tech
Senior

Name the parameters of the @Transactional annotation.

sobes.tech AI

Answer from AI

The @Transactional annotation in Java (Spring Framework) manages transactions at the method or class level. Main parameters:

  • propagation — defines the transaction behavior when called from another transaction (e.g., REQUIRED, REQUIRES_NEW).
  • isolation — the transaction isolation level (READ_COMMITTED, SERIALIZABLE, etc.).
  • timeout — the time in seconds after which the transaction will be interrupted if not completed.
  • readOnly — a flag indicating that the transaction is read-only, which can optimize database operations.
  • rollbackFor and noRollbackFor — exception classes for which the transaction should or should not be rolled back.

Example:

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 30, readOnly = false, rollbackFor = Exception.class)
public void updateData() {
    // business logic
}