? on syntax of container-transaction element of ejb-jar.xml

Discussions

EJB programming & troubleshooting: ? on syntax of container-transaction element of ejb-jar.xml

  1. To keep things simple, I initially set the container-transaction attribute on all my beans to
    <container-transaction>
    <method>
    <ejb-name>base/BeanName</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Required</trans-attribute>
    </container-transaction>

    This of course started a transaction for every call to every method in my bean. I'm beginning to get worried about the performance issues with that arrangement. All my beans are Stateless Session beans and the vast majority of the methods on them just hit the database and return data, and do not need to be part of a transaction.

    How flexible is the syntax for method names? For example, could I setup a rule for <method-name>findBy*</method-name> that would apply to all methods starting with "findBy", then a separate rule for all other methods ("*")? Or is it all or nothing where if you are not setting a global rule, you have to set a rule up for every single method in your bean.

    What I hope to get away with is something like the below syntax where the default is "Requires", but methods that start with "findBy" just have the "Supports" attribute.
    <container-transaction>
    <method>
    <ejb-name>base/BeanName</ejb-name>
    <method-name>findBy*</method-name>
    </method>
    <trans-attribute>Supports</trans-attribute>
    </container-transaction>
    <container-transaction>
    <method>
    <ejb-name>base/BeanName</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>Required</trans-attribute>
    </container-transaction>

    I'm currently running on Oracle9iAS and Orion.

      Thanks

  2. Syntax is flexible enough but not upto a regular expression matching.

    I am giving an example here, which shold explain the syntax.

    <container-transaction>
       <method>
    <ejb-name>EjbA</ejb-name>
    <method-name>*</method-name>
        </method>
       <trans-attribute>Supports</trans-attrubute>
    </container-transaction>

    Above syntax, makes the default rule. If there is no other rule, this rule will be applied. Now toy can override the above rule by using explicit method name. If the method name is overloaded, then the rule will be applicable for all the methods with this method name.

    <container-transaction>
       <method>
    <ejb-name>EjbA</ejb-name>
    <method-name>method1</method-name>
        </method>
       <trans-attribute>Required</trans-attrubute>
    </container-transaction>
    Now for method1, Required will be applicable.

    Suppose, if the method 'method1' is overloaded for two signatures and you want to give different transaction attribute for these two methods you can use the following syntax.

     <container-transaction>
       <method>
    <ejb-name>EjbA</ejb-name>
    <method-name>method1</method-name>
    <method-params>PARAMETER_1</method-params>
    <method-params>PARAMETER_2</method-params>
        </method>
       <trans-attribute>Required</trans-attrubute>
     </container-transaction>

    Hope this helps.

    regards
    sankar
  3. Thanks. That was exactly what I was looking for