5 Replies Latest reply on Sep 25, 2005 8:26 AM by darranl

    2 session beans having a reference to each other can not be

    momo0

      I have 2 session beans creating a reference to each other in their ejbCreate() method. It looks like that the first session bean instance creates the second session bean instance wich creates another instance of the first one and so on. It was hapilly running with Jboss 4.0.0 and previous versions but not any more since version 4.0.2. I made a test program for isolating the problem, I am including the code and the JBoss outputs for JBoss 4.03RC2 and 4.0.0. I would appreciate your help for telling me how to make my test program working with the latest version of JBoss.


      The code of the first session bean is the following:

      package com.hollandhouse.unispool.app.test.circularsbreferencetest;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      /**
       *
       * @ejb.bean name="FirstSession"
       * type="Stateless"
       * jndi-name="FirstSessionHome"
       * local-jndi-name="FirstSessionLocalHome"
       * view-type="both"
       *
       * @ejb.ejb-ref ejb-name="SecondSession"
       * view-type="local"
       * ref-name="ejb/SecondSessionLocalHome"
       *
       */
      public class FirstSessionBean implements SessionBean {
       private SessionContext m_sessionContext;
       private SecondSessionLocal m_secondSessionLocal = null;
      
       /**
       * @ejb.interface-method
       * @ejb.transaction type="Required"
       */
       public void doNothing() {
       }
      
       /**
       * @ejb.create-method
       */
       public void ejbCreate() throws CreateException {
      
       try {
       System.out.println("Creating FirstSessionBean...");
       SecondSessionLocalHome localHomeObject
       = (SecondSessionLocalHome) new InitialContext().lookup(SecondSessionLocalHome.JNDI_NAME);
       m_secondSessionLocal = (SecondSessionLocal) localHomeObject.create();
       System.out.println("Created FirstSessionBean");
       } catch(NamingException e) {
       throw new CreateException("Can not create FirstSessionBean: " + e.getMessage());
       }
       }
      
       public void ejbActivate() throws EJBException, RemoteException {
       }
       public void ejbPassivate() throws EJBException, RemoteException {
       }
       public void ejbRemove() throws EJBException, RemoteException {
       }
       public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {
       m_sessionContext = arg0;
       }
      }
      


      The code of the second one (same as first one):
      package com.hollandhouse.unispool.app.test.circularsbreferencetest;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      /**
       * @ejb.bean name="SecondSession"
       * type="Stateless"
       * jndi-name="SecondSessionHome"
       * local-jndi-name="SecondSessionLocalHome"
       * view-type="both"
       *
       * @ejb.ejb-ref ejb-name="FirstSession"
       * view-type="local"
       * ref-name="ejb/FirstSessionLocalHome"
       */
      public class SecondSessionBean implements SessionBean {
       private SessionContext m_sessionContext;
       private FirstSessionLocal m_firstSessionLocal = null;
      
       /**
       * @ejb.interface-method
       * @ejb.transaction type="Required"
       */
       public void doNothing() {
       }
      
       /**
       * @ejb.create-method
       */
       public void ejbCreate() throws CreateException {
       try {
       System.out.println("Creating SecondSessionBean...");
       FirstSessionLocalHome localHomeObject = (FirstSessionLocalHome) new InitialContext().lookup(FirstSessionLocalHome.JNDI_NAME);
       m_firstSessionLocal = (FirstSessionLocal) localHomeObject.create();
       System.out.println("Created SecondSessionBean");
       } catch(NamingException e) {
       throw new CreateException("Can not create SecondSessionBean: " + e.getMessage());
       }
       }
      
       public void ejbActivate() throws EJBException, RemoteException {
       }
       public void ejbPassivate() throws EJBException, RemoteException {
       }
       public void ejbRemove() throws EJBException, RemoteException {
       }
       public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {
       m_sessionContext = arg0;
       }
      }
      


      The code of the test class:
      package com.hollandhouse.unispool.app.test.circularsbreferencetest;
      
      import java.rmi.RemoteException;
      import java.util.Properties;
      import javax.ejb.CreateException;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class Main {
      
       public static void main(String[] args) throws NamingException, RemoteException, CreateException {
       Properties properties = System.getProperties();
       Context context = new InitialContext(properties);
      
       Object obj = context.lookup(FirstSessionHome.JNDI_NAME);
       FirstSessionHome firstSessionHome = (FirstSessionHome) javax.rmi.PortableRemoteObject.narrow(obj, FirstSessionHome.class);
       // Following create statement fails
       FirstSession firstSession = firstSessionHome.create();
      
       obj = context.lookup(SecondSessionHome.JNDI_NAME);
       SecondSessionHome secondSessionHome = (SecondSessionHome) javax.rmi.PortableRemoteObject.narrow(obj, SecondSessionHome.class);
       SecondSession secondSession = secondSessionHome.create();
      
       firstSession.doNothing();
       secondSession.doNothing();
       }
      }
      


      the Jboss output (JBoss version 4.0.3RC2):
      ....
      10:17:59,656 INFO [STDOUT] Creating FirstSessionBean...
      10:17:59,671 INFO [STDOUT] Creating SecondSessionBean...
      10:17:59,671 INFO [STDOUT] Creating FirstSessionBean...
      10:17:59,671 INFO [STDOUT] Creating SecondSessionBean...
      10:17:59,671 INFO [STDOUT] Creating FirstSessionBean...
      10:17:59,687 INFO [STDOUT] Creating SecondSessionBean...
      ....
      ... and so on until
      10:17:59,890 ERROR [LogInterceptor] TransactionRolledbackLocalException in metho
      d: public abstract com.hollandhouse.unispool.app.test.circularsbreferencetest.Se
      condSessionLocal com.hollandhouse.unispool.app.test.circularsbreferencetest.Seco
      ndSessionLocalHome.create() throws javax.ejb.CreateException, causedBy:
      java.lang.reflect.UndeclaredThrowableException
       at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.j
      ava:189)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(
      StatelessSessionInstanceInterceptor.java:80)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      tor.java:90)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValida
      tionInterceptor.java:41)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:109)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:335)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
      va:146)
       at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
      tor.java:116)
       at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
      21)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyF
      actoryFinderInterceptor.java:93)
       at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.ja
      va:613)
       at org.jboss.ejb.Container.invoke(Container.java:894)
       at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLoca
      lProxyFactory.java:344)
       at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java
      :118)
       at $Proxy236.create(Unknown Source)
       at com.hollandhouse.unispool.app.test.circularsbreferencetest.FirstSessi
      onBean.ejbCreate(FirstSessionBean.java:44)
       at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.StatelessSessionEnterpriseContext.<init>(StatelessSessi
      onEnterpriseContext.java:63)
       at org.jboss.ejb.plugins.StatelessSessionInstancePool.create(StatelessSe
      ssionInstancePool.java:35)
       at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.j
      ava:169)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(
      StatelessSessionInstanceInterceptor.java:80)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      tor.java:90)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValida
      tionInterceptor.java:41)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:109)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:335)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
      va:146)
       at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
      tor.java:116)
       at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
      21)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyF
      actoryFinderInterceptor.java:93)
       at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.ja
      va:613)
       at org.jboss.ejb.Container.invoke(Container.java:894)
       at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLoca
      lProxyFactory.java:344)
       at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java
      :118)
       at $Proxy237.create(Unknown Source)
       at com.hollandhouse.unispool.app.test.circularsbreferencetest.SecondSess
      ionBean.ejbCreate(SecondSessionBean.java:41)
       at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.StatelessSessionEnterpriseContext.<init>(StatelessSessi
      onEnterpriseContext.java:63)
       at org.jboss.ejb.plugins.StatelessSessionInstancePool.create(StatelessSe
      ssionInstancePool.java:35)
       at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.j
      ava:169)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(
      StatelessSessionInstanceInterceptor.java:80)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      tor.java:90)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValida
      tionInterceptor.java:41)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:109)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:335)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
      va:146)
       at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
      tor.java:116)
       at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
      21)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyF
      actoryFinderInterceptor.java:93)
       at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.ja
      va:613)
       at org.jboss.ejb.Container.invoke(Container.java:894)
       at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLoca
      lProxyFactory.java:344)
       at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java
      :118)
       at $Proxy236.create(Unknown Source)
       at com.hollandhouse.unispool.app.test.circularsbreferencetest.FirstSessi
      onBean.ejbCreate(FirstSessionBean.java:44)
       at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.StatelessSessionEnterpriseContext.<init>(StatelessSessi
      onEnterpriseContext.java:63)
       at org.jboss.ejb.plugins.StatelessSessionInstancePool.create(StatelessSe
      ssionInstancePool.java:35)
       at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.j
      ava:169)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(
      StatelessSessionInstanceInterceptor.java:80)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      tor.java:90)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValida
      tionInterceptor.java:41)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:109)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:335)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
      va:146)
       at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
      tor.java:116)
       at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
      21)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyF
      actoryFinderInterceptor.java:93)
       at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.ja
      va:613)
       at org.jboss.ejb.Container.invoke(Container.java:894)
       at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLoca
      lProxyFactory.java:344)
       at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java
      :118)
       at $Proxy237.create(Unknown Source)
       at com.hollandhouse.unispool.app.test.circularsbreferencetest.SecondSess
      ionBean.ejbCreate(SecondSessionBean.java:41)
       at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.StatelessSessionEnterpriseContext.<init>(StatelessSessi
      onEnterpriseContext.java:63)
       at org.jboss.ejb.plugins.StatelessSessionInstancePool.create(StatelessSe
      ssionInstancePool.java:35)
       at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.j
      ava:169)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invokeHome(
      StatelessSessionInstanceInterceptor.java:80)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIntercep
      tor.java:90)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValida
      tionInterceptor.java:41)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:109)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:335)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
      va:146)
       at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
      tor.java:116)
       at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
      21)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyF
      actoryFinderInterceptor.java:93)
       at org.jboss.ejb.SessionContainer.internalInvokeHome(SessionContainer.ja
      va:613)
       at org.jboss.ejb.Container.invoke(Container.java:894)
       at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLoca
      lProxyFactory.java:344)
       at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java
      :118)
       at $Proxy236.create(Unknown Source)
      
      
      
      ...
      
      
      It goes on until java.lang.OutOfMemoryErrorout exceptions are thrown.
      
      


      the Jboss output (JBoss version 4.0.0):
      ....
      11:37:09,281 INFO [STDOUT] Creating FirstSessionBean...
      11:37:09,312 INFO [STDOUT] Created FirstSessionBean
      11:37:16,296 INFO [STDOUT] Creating SecondSessionBean...
      11:37:16,312 INFO [STDOUT] Created SecondSessionBean
      


      Note that the 4 log messages indicating creating and created steps appears on the JBoss console when the methods doNothing() are executed and not when the create() methods are called.