Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT

## grails.transaction
[Java] Annotation Type Transactional

    java.lang.Object
      grails.transaction.Transactional

    @java.lang.annotation.Target({ElementType.METHOD, ElementType.TYPE})
    @java.lang.annotation.Retention(RetentionPolicy.RUNTIME)
    @java.lang.annotation.Inherited
    @java.lang.annotation.Documented
    @org.codehaus.groovy.transform.GroovyASTTransformationClass("org.codehaus.groovy.grails.transaction.transform.TransactionalTransform")
    public @interface Transactional

Describes transaction attributes on a method or class.

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

For specific information about the semantics of this annotation's attributes, consider the org.springframework.transaction.TransactionDefinition and org.springframework.transaction.interceptor.TransactionAttribute javadocs.

Authors:
  Graeme Rocher
  Juergen Hoeller

Since:
  2.3

Optional Element Summary
`boolean` | `inheritRollbackOnly` In Spring, when there are nested transaction calls, the execution of the outermost callback will throw UnexpectedRollbackException if TransactionStatus.setRollbackOnly() was called in a nested transaction callback.
`org.springframework.transaction.annotation.Isolation` | `isolation` The transaction isolation level.
`java.lang.Class` | `noRollbackFor` Defines zero (0) or more exception java.lang.Class, which must be a subclass of java.lang.Throwable, indicating which exception types must not cause a transaction rollback.
`java.lang.String` | `noRollbackForClassName` Defines zero (0) or more exception names (for exceptions which must be a subclass of java.lang.Throwable) indicating which exception types must not cause a transaction rollback.
`org.springframework.transaction.annotation.Propagation` | `propagation` The transaction propagation type.
`boolean` | `readOnly` `true` if the transaction is read-only.
`java.lang.Class` | `rollbackFor` Defines zero (0) or more exception java.lang.Class, which must be a subclass of java.lang.Throwable, indicating which exception types must cause a transaction rollback.
`java.lang.String` | `rollbackForClassName` Defines zero (0) or more exception names (for exceptions which must be a subclass of java.lang.Throwable), indicating which exception types must cause a transaction rollback.
`int` | `timeout` The timeout for this transaction.
`java.lang.String` | `value` A qualifier value for the specified transaction.

Method Summary

Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Element Detail

### inheritRollbackOnly

    public boolean inheritRollbackOnly

  In Spring, when there are nested transaction calls, the execution of the outermost callback will throw UnexpectedRollbackException if TransactionStatus.setRollbackOnly() was called in a nested transaction callback. This feature will make the setRollbackOnly state get inherited to parent level transaction template calls and therefore prevent UnexpectedRollbackException. The default value is true. @default true

### isolation

    public org.springframework.transaction.annotation.Isolation isolation

  The transaction isolation level. Defaults to org.springframework.transaction.annotation.Isolation#DEFAULT. @default Isolation.DEFAULT
  See Also:
    org.springframework.transaction.interceptor.TransactionAttribute#getIsolationLevel()

### noRollbackFor

    public java.lang.Class[] noRollbackFor

  Defines zero (0) or more exception java.lang.Class, which must be a subclass of java.lang.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 org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class clazz) @default {}

### noRollbackForClassName

    public java.lang.String[] noRollbackForClassName

  Defines zero (0) or more exception names (for exceptions which must be a subclass of java.lang.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 org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String exceptionName) @default {}

### propagation

    public org.springframework.transaction.annotation.Propagation propagation

  The transaction propagation type. Defaults to org.springframework.transaction.annotation.Propagation#REQUIRED. @default Propagation.REQUIRED
  See Also:
    org.springframework.transaction.interceptor.TransactionAttribute#getPropagationBehavior()

### readOnly

    public boolean readOnly

  `true` if the transaction is read-only. Defaults to `false`.

  This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction. @default false

  See Also:
    org.springframework.transaction.interceptor.TransactionAttribute#isReadOnly()

### rollbackFor

    public java.lang.Class[] rollbackFor

  Defines zero (0) or more exception java.lang.Class, which must be a subclass of java.lang.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 org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class clazz) @default {}

### rollbackForClassName

    public java.lang.String[] rollbackForClassName

  Defines zero (0) or more exception names (for exceptions which must be a subclass of java.lang.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 javax.servlet.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 java.lang.Exception names such as "BaseBusinessException" there is no need to use a FQN.

  Similar to org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String exceptionName) @default {}

### timeout

    public int timeout

  The timeout for this transaction. Defaults to the default timeout of the underlying transaction system. @default TransactionDefinition.TIMEOUT_DEFAULT
  See Also:
    org.springframework.transaction.interceptor.TransactionAttribute#getTimeout()

### value

    public java.lang.String value

  A qualifier value for the specified transaction.

  May be used to determine the target transaction manager, matching the qualifier value (or the bean name) of a specific org.springframework.transaction.PlatformTransactionManager bean definition. @default ""

Groovy Documentation