org.springframework.transaction.annotation
Annotation Type Transactional


@Target(value={METHOD,TYPE})
@Retention(value=RUNTIME)
@Inherited
@Documented
public @interface Transactional

Describes transaction attributes on a method or class.

This annotation type is generally directly comparable to Spring's RuleBasedTransactionAttribute class, and in fact AnnotationTransactionAttributeSource will directly convert the data to the latter class, so that Spring's transaction support code does not have to know about annotations. If no rules are relevant to the exception, it will be treated like DefaultTransactionAttribute (rolling back on runtime exceptions).

Since:
1.2
Author:
Colin Sampaleanu, Juergen Hoeller
See Also:
DefaultTransactionAttribute, RuleBasedTransactionAttribute

Optional Element Summary
 Isolation isolation
          The transaction isolation level.
 Class<? extends Throwable>[] noRollbackFor
          Defines zero (0) or more exception Classes, which must be a subclass of Throwable, indicating which exception types must not cause a transaction rollback.
 String[] noRollbackForClassName
          Defines zero (0) or more exception names (for exceptions which must be a subclass of Throwable) indicating which exception types must not cause a transaction rollback.
 Propagation propagation
          The transaction propagation type.
 boolean readOnly
          true if the transaction is read-only.
 Class<? extends Throwable>[] rollbackFor
          Defines zero (0) or more exception classes, which must be a subclass of Throwable, indicating which exception types must cause a transaction rollback.
 String[] rollbackForClassName
          Defines zero (0) or more exception names (for exceptions which must be a subclass of Throwable), indicating which exception types must cause a transaction rollback.
 int timeout
          The timeout for this transaction.
 

propagation

public abstract Propagation propagation
The transaction propagation type.

Defaults to Propagation.REQUIRED.

Default:
org.springframework.transaction.annotation.Propagation.REQUIRED

isolation

public abstract Isolation isolation
The transaction isolation level.

Defaults to Isolation.DEFAULT.

Default:
org.springframework.transaction.annotation.Isolation.DEFAULT

timeout

public abstract int timeout
The timeout for this transaction.

Defaults to the default timeout of the underlying transaction system.

Default:
-1

readOnly

public abstract boolean readOnly
true if the transaction is read-only.

Defaults to false.

Default:
false

rollbackFor

public abstract Class<? extends Throwable>[] rollbackFor
Defines zero (0) or more exception classes, which must be a subclass of Throwable, indicating which exception types must cause a transaction rollback.

This is the preferred way to construct a rollback rule, matching the exception class and subclasses.

Similar to RollbackRuleAttribute.RollbackRuleAttribute(Class clazz)

Default:
{}

rollbackForClassName

public abstract String[] rollbackForClassName
Defines zero (0) or more exception names (for exceptions which must be a subclass of Throwable), indicating which exception types must cause a transaction rollback.

This can be a substring, with no wildcard support at present. A value of "ServletException" would match ServletException and subclasses, for example.

NB: Consider carefully how specific the pattern is, and whether to include package information (which isn't mandatory). For example, "Exception" will match nearly anything, and will probably hide other rules. "java.lang.Exception" would be correct if "Exception" was meant to define a rule for all checked exceptions. With more unusual Exception names such as "BaseBusinessException" there is no need to use a FQN.

Similar to RollbackRuleAttribute.RollbackRuleAttribute(String exceptionName)

Default:
{}

noRollbackFor

public abstract Class<? extends Throwable>[] noRollbackFor
Defines zero (0) or more exception Classes, which must be a subclass of Throwable, indicating which exception types must not cause a transaction rollback.

This is the preferred way to construct a rollback rule, matching the exception class and subclasses.

Similar to NoRollbackRuleAttribute.NoRollbackRuleAttribute(Class clazz)

Default:
{}

noRollbackForClassName

public abstract String[] noRollbackForClassName
Defines zero (0) or more exception names (for exceptions which must be a subclass of Throwable) indicating which exception types must not cause a transaction rollback.

See the description of rollbackForClassName() for more info on how the specified names are treated.

Similar to NoRollbackRuleAttribute.NoRollbackRuleAttribute(String exceptionName)

Default:
{}


Copyright © 2002-2008 The Spring Framework.