More DD examples for CMT

Option 1: Wildcard

Use a wildcard to say that all methods in the specified bean have the attribute in the <trans-attribute> tag.

image with no caption

Option 2: Individually-named methods

Specify each method of each CMT bean in the ejb-jar (unless you use the wildcard to indicate all methods of the specified bean class have the specified attribute).

Note

Here we have three different methods, in one bean, that all have the RequiresNew attribute.

<container-transaction>
     <method>
        <ejb-name>BigBean</ejb-name>
        <method-name>foo</method-name>
     </method>
     <method>
        <ejb-name>BigBean</ejb-name>
        <method-name>go</method-name>
     </method>
     <method>
        <ejb-name>BigBean</ejb-name>
        <method-name>bar</method-name>
     </method>
     <trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
<container-transaction>
     <method>
        <ejb-name>BigBean</ejb-name>
        <method-name>doStuff</method-name>
     </method>
     <trans-attribute>Required</trans-attribute>
 </container-transaction>

Note

This is a different transaction attribute -- Requires -- so here we list the method that uses Requires. Notice that we’re naming the same bean we used in the previous <container-transaction> element.

image with no caption

Don’t worry.

Chances are, your design will treat all versions of an overloaded method in the same way (for transactions). In the examples we’ve seen ...

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.