Annotation Interface TransactionalTry


@DmxTransactionalBinding @InterceptorBinding @Inherited @Documented @Retention(RUNTIME) @Target({TYPE,METHOD}) public @interface TransactionalTry
Declarative transaction annotation for methods that return Try.

When applied to a CDI bean method, TransactionalDmxInterceptor intercepts the call and wraps the body in a JTA transaction. The transaction commits when the method returns Try.isSuccess() and rolls back when it returns Try.isFailure() or when an unchecked exception escapes.

Quick start

@ApplicationScoped
public class ReportService {

    @TransactionalTry
    public Try<Report> generate(ReportRequest req) {
        return Try.of(() -> reportRepo.save(build(req)))
            .map(r -> { auditLog.record(r); return r; });
    }

    // Always start a fresh transaction, independent of any outer one.
    @TransactionalTry(Transactional.TxType.REQUIRES_NEW)
    public Try<AuditEntry> audit(Event event) { ... }
}

Transaction semantics

  • Transactional.TxType.REQUIRED (default) — join an existing transaction or begin a new one.
  • Transactional.TxType.REQUIRES_NEW — always suspend any active transaction and begin a fresh one; the new transaction commits or rolls back independently.
  • Transactional.TxType.MANDATORY — require an active transaction; throw TransactionalException if none exists.
  • Transactional.TxType.SUPPORTS — join an active transaction if present; otherwise execute without one.
  • Transactional.TxType.NOT_SUPPORTED — suspend any active transaction and execute without one; resume it afterwards.
  • Transactional.TxType.NEVER — throw TransactionalException if a transaction is active.
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    jakarta.transaction.Transactional.TxType
    The transaction propagation type.
  • Element Details

    • value

      jakarta.transaction.Transactional.TxType value
      The transaction propagation type.

      Marked Nonbinding so that CDI selects the same interceptor regardless of the chosen Transactional.TxType; the interceptor reads the value at runtime.

      Default:
      REQUIRED