Annotation Interface TransactionScoped


@Retention(RUNTIME) @Target({TYPE,METHOD,FIELD}) @NormalScope(passivating=true) public @interface TransactionScoped

The jakarta.transaction.TransactionScoped annotation provides the ability to specify a standard CDI scope to define bean instances whose lifecycle is scoped to the currently active Jakarta Transactions transaction. This annotation has no effect on classes which have non-contextual references such those defined as managed beans by the Jakarta EE specification.

The transaction scope is active when the return from a call to UserTransaction.getStatus or TransactionManager.getStatus is one of the following states:
  • Status.STATUS_ACTIVE
  • Status.STATUS_MARKED_ROLLBACK
  • Status.STATUS_PREPARED
  • Status.STATUS_UNKNOWN
  • Status.STATUS_PREPARING
  • Status.STATUS_COMMITTING
  • Status.STATUS_ROLLING_BACK

It is not intended that the term "active" as defined here in relation to the TransactionScoped annotation should also apply to its use in relation to transaction context, lifecycle, etc. mentioned elsewhere in this specification. The object with this annotation will be associated with the current active Jakarta Transactions transaction when the object is used. This association must be retained through any transaction suspend or resume calls as well as any Synchronization.beforeCompletion callbacks. Any Synchronization.afterCompletion methods will be invoked in an undefined context. The way in which the Jakarta Transactions transaction is begun and completed (for example via UserTransaction, Transactional interceptor, etc.) is of no consequence. The contextual references used across different Jakarta Transactions transactions are distinct. Refer to the CDI specification for more details on contextual references. A jakarta.enterprise.context.ContextNotActiveException will be thrown if an object with this annotation is used when the transaction context is not active.

Since:
JTA 1.2
Version:
Jakarta Transactions 2.0