Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Usage of the @TransactionAttribute requires you to specify one of six different transaction attribute types defined via the javax.ejb.TransactionAttributeType enum.

  • TransactionAttributeType.MANDATORY
  • TransactionAttributeType.REQUIRED
  • TransactionAttributeType.REQUIRES_NEW
  • TransactionAttributeType.SUPPORTS
  • TransactionAttributeType.NOT_SUPPORTED
  • TransactionAttributeType.NEVER

Per EJB 3.0 the default transaction attribute for all EJB 3.0 applications is REQUIRED. The default transaction attribute for EJB 2.1, 2.0 and 1.1 applications is vendor specific. In OpenEJB EJB 2.1, 2.0 and 1.1 applications also use REQUIRED as the default.

...

Code Block
@Stateless
public static class MyBean implements MyBusinessInterface {

    @TransactionAttribute(TransactionAttributeType.MANDATORY)
    public String codeRed(String s) {
        return s;
    }

    public String codeBlue(String s) {
        return s;
    }
}
  • codeRed will be invoked with the attribute of MANDATORY
  • codeBlue will be invoked with the default attribute of REQUIRED

On Classes

Code Block
@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public static class MyBean implements MyBusinessInterface {

    public String codeRed(String s) {
        return s;
    }

    public String codeBlue(String s) {
        return s;
    }
}
  • codeRed and codeBlue will be invoked with the attribute of MANDATORY

Mixed on classes and methods

Code Block
@Stateless
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public static class MyBean implements MyBusinessInterface {

    @TransactionAttribute(TransactionAttributeType.NEVER)
    public String codeRed(String s) {
        return s;
    }

    public String codeBlue(String s) {
        return s;
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public String codeGreen(String s) {
        return s;
    }
}
  • codeRed will be invoked with the attribute of NEVER
  • codeBlue will be invoked with the attribute of SUPPORTS
  • codeGreen will be invoked with the attribute of REQUIRED

Illegal Usage

Generally, transaction annotationss cannot be made on AroundInvoke methods and most callbacks.

...