Top Description Inners Methods
javax.transaction

public @Interface Transactional

extends Annotation
Annotations
@Inherited
@InterceptorBinding
@Target:TYPE, METHOD
@Retention:RUNTIME
Imports
javax.enterprise.util.Nonbinding, javax.interceptor.InterceptorBinding, java.lang.annotation.*

The javax.transaction.Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans, as well as classes defined as managed beans by the Java EE specification, at both the class and method level where method level annotations override those at the class level.

See the EJB specification for restrictions on the use of @Transactional with EJBs.

This support is provided via an implementation of CDI interceptors that conduct the necessary suspending, resuming, etc. The Transactional interceptor interposes on business method invocations only and not on lifecycle events. Lifecycle methods are invoked in an unspecified transaction context.

If an attempt is made to call any method of the UserTransaction interface from within the scope of a bean or method annotated with @Transactional and a Transactional.TxType other than NOT_SUPPORTED or NEVER, an IllegalStateException must be thrown. The use of the UserTransaction is allowed within life cycle events. The use of the TransactionSynchronizationRegistry is allowed regardless of any @Transactional annotation.

The Transactional interceptors must have a priority of Interceptor.Priority.PLATFORM_BEFORE+200. Refer to the Interceptors specification for more details.

The TxType element of the annotation indicates whether a bean method is to be executed within a transaction context. TxType.REQUIRED is the default.

By default checked exceptions do not result in the transactional interceptor marking the transaction for rollback and instances of RuntimeException and its subclasses do. This default behavior can be modified by specifying exceptions that result in the interceptor marking the transaction for rollback and/or exceptions that do not result in rollback.

The rollbackOn element can be set to indicate exceptions that must cause the interceptor to mark the transaction for rollback.

Conversely, the dontRollbackOn element can be set to indicate exceptions that must not cause the interceptor to mark the transaction for rollback.

When a class is specified for either of these elements, the designated behavior applies to subclasses of that class as well. If both elements are specified, dontRollbackOn takes precedence.

Since
JTA1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Transactional.TxType

The TxType element of the annotation indicates whether a bean method is to be executed within a transaction context where the values provide the following corresponding behavior.

Method Summary

Modifier and TypeMethod and Description
public Class<T>[]

Returns:

Class[] of Exceptions
dontRollbackOn
()

The dontRollbackOn element can be set to indicate exceptions that must not cause the interceptor to mark the transaction for rollback.

public Class<T>[]

Returns:

Class[] of Exceptions
rollbackOn
()

The rollbackOn element can be set to indicate exceptions that must cause the interceptor to mark the transaction for rollback.

public Transactional.TxType
value()

The TxType element of the Transactional annotation indicates whether a bean method is to be executed within a transaction context.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

dontRollbackOnback to summary
public Class<T>[] dontRollbackOn()

The dontRollbackOn element can be set to indicate exceptions that must not cause the interceptor to mark the transaction for rollback. Conversely, the rollbackOn element can be set to indicate exceptions that must cause the interceptor to mark the transaction for rollback. When a class is specified for either of these elements, the designated behavior applies to subclasses of that class as well. If both elements are specified, dontRollbackOn takes precedence.

Returns:Class<T>[]

Class[] of Exceptions

Annotations
@Nonbinding
rollbackOnback to summary
public Class<T>[] rollbackOn()

The rollbackOn element can be set to indicate exceptions that must cause the interceptor to mark the transaction for rollback. Conversely, the dontRollbackOn element can be set to indicate exceptions that must not cause the interceptor to mark the transaction for rollback. When a class is specified for either of these elements, the designated behavior applies to subclasses of that class as well. If both elements are specified, dontRollbackOn takes precedence.

Returns:Class<T>[]

Class[] of Exceptions

Annotations
@Nonbinding
valueback to summary
public Transactional.TxType value()

The TxType element of the Transactional annotation indicates whether a bean method is to be executed within a transaction context.

javax.transaction back to summary

public final Enum Transactional.TxType

extends Enum<Transactional.TxType>
Class Inheritance

The TxType element of the annotation indicates whether a bean method is to be executed within a transaction context where the values provide the following corresponding behavior.

Field Summary

Modifier and TypeField and Description
public static final Transactional.TxType
MANDATORY

If called outside a transaction context, a TransactionalException with a nested TransactionRequiredException must be thrown.

public static final Transactional.TxType
NEVER

If called outside a transaction context, managed bean method execution must then continue outside a transaction context.

public static final Transactional.TxType
NOT_SUPPORTED

If called outside a transaction context, managed bean method execution must then continue outside a transaction context.

public static final Transactional.TxType
REQUIRED

If called outside a transaction context, the interceptor must begin a new JTA transaction, the managed bean method execution must then continue inside this transaction context, and the transaction must be completed by the interceptor.

public static final Transactional.TxType
REQUIRES_NEW

If called outside a transaction context, the interceptor must begin a new JTA transaction, the managed bean method execution must then continue inside this transaction context, and the transaction must be completed by the interceptor.

public static final Transactional.TxType
SUPPORTS

If called outside a transaction context, managed bean method execution must then continue outside a transaction context.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Transactional.TxType
public static Transactional.TxType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

MANDATORYback to summary
public static final Transactional.TxType MANDATORY

If called outside a transaction context, a TransactionalException with a nested TransactionRequiredException must be thrown.

If called inside a transaction context, managed bean method execution will then continue under that context.

NEVERback to summary
public static final Transactional.TxType NEVER

If called outside a transaction context, managed bean method execution must then continue outside a transaction context.

If called inside a transaction context, a TransactionalException with a nested InvalidTransactionException must be thrown.

NOT_SUPPORTEDback to summary
public static final Transactional.TxType NOT_SUPPORTED

If called outside a transaction context, managed bean method execution must then continue outside a transaction context.

If called inside a transaction context, the current transaction context must be suspended, the managed bean method execution must then continue outside a transaction context, and the previously suspended transaction must be resumed by the interceptor that suspended it after the method execution has completed.

REQUIREDback to summary
public static final Transactional.TxType REQUIRED

If called outside a transaction context, the interceptor must begin a new JTA transaction, the managed bean method execution must then continue inside this transaction context, and the transaction must be completed by the interceptor.

If called inside a transaction context, the managed bean method execution must then continue inside this transaction context.

REQUIRES_NEWback to summary
public static final Transactional.TxType REQUIRES_NEW

If called outside a transaction context, the interceptor must begin a new JTA transaction, the managed bean method execution must then continue inside this transaction context, and the transaction must be completed by the interceptor.

If called inside a transaction context, the current transaction context must be suspended, a new JTA transaction will begin, the managed bean method execution must then continue inside this transaction context, the transaction must be completed, and the previously suspended transaction must be resumed.

SUPPORTSback to summary
public static final Transactional.TxType SUPPORTS

If called outside a transaction context, managed bean method execution must then continue outside a transaction context.

If called inside a transaction context, the managed bean method execution must then continue inside this transaction context.

Constructor Detail

TxTypeback to summary
private TxType()

Method Detail

valueOfback to summary
public static Transactional.TxType valueOf(String name)
valuesback to summary
public static Transactional.TxType[] values()