Thursday, June 28, 2012

Default Transaction Attribute for EJBs

Default transaction attributes differ from container to container.
In Weblogic Server, default transaction attribute for MDB is NotSupported however for all other EJBs is Supports for version 10.0 onwards - if no attribute value is specified for trans-attribute in the ejb deployment descriptor.

Container-Managed Transaction Elements in ejb-jar.xml (WebLogic Server 10.x)

Element: transaction-type
Description: Allowable values are Bean or Container.
Default: None, EJB 2.x requires this attribute to be specified.


Element: trans-attribute
Description: 
Specifies how the container manages the transaction boundaries when delegating a method invocation to an enterprise bean's business method. Allowable values are:
  • NotSupported
  • With the NotSupported value, when an entity bean runs in an unspecified transaction, if a transaction exists, the EJB container suspends the transaction; when an entity bean runs in an unspecified transaction, and no transaction exists, the EJB container takes no action.
  • Supports
  • With the Supports value, when an entity bean runs in an unspecified transaction, if a transaction exists, the EJB container uses the current transaction; when an entity bean runs in an unspecified transaction, and no transaction exists, the EJB container takes no action.
  • Required
  • RequiresNew
  • Mandatory
  • Never
  • With the Never value, when an entity bean runs in an unspecified transaction, if a transaction exists, the EJB container throws an exception; when an entity bean runs in an unspecified transaction, and no transaction exists, the EJB container takes no action.
Note: In in pre-9.0 releases of WebLogic Server, the EJB container would start a new transaction when no transaction existed and the value of trans-attribute was NotSupportedSupports, and Never. Set entity-always-uses-transaction inweblogic-ejb-jar.xml to True if you want the EJB container to behave as it did in pre-9.0 releasesof WebLogic Server and create a new transaction.

Because clients do not provide a transaction context for calls to an MDB, MDBs that use container-managed transactions must have trans-attribute of Required.


Default: If not specified, the EJB container issues a warning, and usesNotSupported for MDBs and Supportsfor other types of EJBs.

Element: transaction-scope
Description: 
This optional element specifies whether an enterprise bean requires distributed transactions for its methods or whether the local transaction optimization may be used.
Allowable values are Local and Distributed.

Default: If not specified, the container assumes that distributed transactions must be used.


Reference: http://docs.oracle.com/cd/E11035_01/wls100/ejb/implementing.html#wp1150418

No comments: