O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required