4 Replies Latest reply on Sep 13, 2010 9:37 AM by Radosław Szulgo

    Calling ejb2.1 business method in transaction from ejb3

    Radosław Szulgo Newbie

      Greetings,

      I have an issue related to the call of ejb2.1 business method that has to be  executed in transaction by en ejb3 method. The ejb2.1 and ejb3 are managed by container and ejb3 creates and uses a Remote interface of ejb2.1. The ejb2 business method is defined in ejb-jar.xml as follows:

       

       

      <container-transaction>
           <method>
                <ejb-name>Document</ejb-name>
                <method-name>set</method-name>
           </method>
           <trans-attribute>Mandatory</trans-attribute>
      </container-transaction>
      
      <container-transaction>
      <method>
      <ejb-name>Document</ejb-name>
      <method-name>set</method-name>
      </method>
      <trans-attribute>Mandatory</trans-attribute>
      </container-transaction>

       

      So the caller (ejb3) of method set() needs to start a transaction. I decorated that ejb3 method with:

       

       

      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      

       

      to start a new transaction, however I get an exception:

       

      javax.transaction.TransactionRequiredException: Transaction Required
           at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:426)
           at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
           at org.jboss.ejb.plugins.security.PreSecurityInterceptor.process(PreSecurityInterceptor.java:97)
           at org.jboss.ejb.plugins.security.PreSecurityInterceptor.invoke(PreSecurityInterceptor.java:81)
           at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
           at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:138)
           at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:650)
           at org.jboss.ejb.Container.invoke(Container.java:1029)
           at sun.reflect.GeneratedMethodAccessor359.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
           at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)
           at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)
           at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:209)
           at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:195)
           at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
           at org.jboss.proxy.ejb.SecurityContextInterceptor.invoke(SecurityContextInterceptor.java:64)
           at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:68)
           at org.jboss.proxy.ejb.StatefulSessionInterceptor.invoke(StatefulSessionInterceptor.java:118)
           at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:101)
           at $Proxy254.set(Unknown Source)
           at pg.seti.ad.dict.ejb3.DictManagerBean.saveDict(DictManagerBean.java:270)
      

       

      When I've changed in the ejb-jar.xml descriptor <trans-attribute> value from Mandatory to RequiresNew to start new transaction whenever the transaction was started or not, the exception doesn't occurs. It looks like the transaction does not propagate from ejb3 to ejb2.1.

       

      Any help greatly appreciated, thanks.