7 Replies Latest reply on Jun 9, 2008 4:50 AM by John smith

    Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-792

    olivier merlin Newbie

      Hello,
      We try to migrate a big glassfish application to jboss, but we have a blocking issue with cyclic depencies on EJB3.
      The JIRA EJBTHREE-792 identified this issue as resolved thru the @IgnoreDependency annotation.
      This is not so simple - this does not work for us at all.

      I explain :

      First at all it does not work at all for ejb-jar.xml deployment descriptor file.
      There is no standard annotation IgnoreDepency even in jboss.xml, the jboss "not in spec" descriptor file.
      We then try to move the ejb-jar.xml injection into the code directly with the @EJB annotations as indicated in EJBTHREE-792 .

      It works for very simple code with @EJB injection without name references.
      But if you add name parameters it does not work anymore. We need parameters to @EJB to specify implementation. (our Glassfish code use this)

      You can try with this simple code :

      Hello1Bean class:

      @EJBs(
      { @EJB(name="ejb/Hello2", beanInterface=Hello2.class, beanName="Hello2Bean")

      })

      public @Stateless class Hello1Bean implements Hello1 {

      @IgnoreDependency
      @EJB(name="ejb/Hello2")
      private Hello2 hello;

      Hello2Bean Class :

      @EJBs(
      {@EJB(name="ejb/Hello1", beanInterface=Hello1.class,beanName="Hello1Bean")

      })
      public @Stateless class Hello2LocalBean implements Hello2Local {

      @IgnoreDependency
      @EJB(name="ejb/Hello1")
      private Hello1 hello;

      You then get the following dependency error :
      --- MBeans waiting for other MBeans ---
      ObjectName: jboss.j2ee:jar=cyclic.jar,name=Hello2Bean,service=EJB3
      State: NOTYETINSTALLED
      I Depend On:
      jboss.j2ee:jar=cyclic.jar,name=Hello1Bean,service=EJB3
      Depends On Me:
      jboss.j2ee:jar=cyclic.jar,name=Hello1Bean,service=EJB3

      ObjectName: jboss.j2ee:jar=cyclic.jar,name=Hello1Bean,service=EJB3
      State: NOTYETINSTALLED
      I Depend On:
      jboss.j2ee:jar=cyclic.jar,name=Hello2Bean,service=EJB3
      Depends On Me:
      jboss.j2ee:jar=cyclic.jar,name=Hello2Bean,service=EJB3


      We have the problem in both 4.2.2 & 5.0Beta3 versions.
      We have currently no solution,no working workaround.

      Need help,
      thanks,
      Olivier

        • 1. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
          jaikiran pai Master

           

          "omerlin" wrote:

          We have the problem in both 4.2.2 & 5.0Beta3 versions.
          We have currently no solution,no working workaround.


          Remove the class level @EJBs declaration. And let your beans look like this:
          Hello1Bean class:
          
          @Stateless
          public class Hello1Bean implements Hello1 {
          
          @IgnoreDependency
          @EJB(name="ejb/Hello2")
          private Hello2 hello;
          
          }
          
          Hello2Bean Class :
          
          @Stateless
          public class Hello2LocalBean implements Hello2Local {
          
          @IgnoreDependency
          @EJB(name="ejb/Hello1")
          private Hello1 hello;
          
          }
          
          


          Whatever, you are trying to do with the @EJBs at the class level can be achieved by this change.



          • 2. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
            John smith Newbie

            hi Olivier, i have posted the same problem here: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=136978

            I will try this proposal, i hope that it will work !


            • 3. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
              John smith Newbie


              this does not work when the interface has several implementations, in this case the following error is generated:

              could not resolve global JNDI name for @EJB for container Hello1Bean : reference class: com.gemalto.session.Hello2Local ejbLink: duplicated in cyclic.jar


              the question is: how to not use the declaration of reference with EJBs when the interface has several implementations?

              Thank's

              • 4. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
                jaikiran pai Master

                Please post the entire exception stacktrace. Also post the bean definitions(with annotations) that you are using (the interface and the multiple implementations).

                • 5. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
                  jaikiran pai Master

                   

                  "Nouredine13" wrote:

                  this does not work when the interface has several implementations, in this case the following error is generated:

                  could not resolve global JNDI name for @EJB for container Hello1Bean : reference class: com.gemalto.session.Hello2Local ejbLink: duplicated in cyclic.jar


                  the question is: how to not use the declaration of reference with EJBs when the interface has several implementations?

                  Thank's


                  I think i understand what you are saying. If you have multiple (bean) implementations for the same interface, you can inject the beans as follows:
                  
                  Hello1Bean class:
                  
                  
                  @Stateless
                  public class Hello1Bean implements Hello1 {
                  
                  @IgnoreDependency
                  @EJB(name="ejb/Hello2",beanName="Hello2Bean")
                  private Hello2 hello;
                  
                  }
                  
                  
                  Hello2Bean Class :
                  
                  
                  @Stateless
                  public class Hello2LocalBean implements Hello2Local {
                  
                  @IgnoreDependency
                  @EJB(name="ejb/Hello1",beanName="Hello1Bean")
                  private Hello1 hello;
                  
                  }


                  Note, the use of beanName in the @EJB annotation at field level. If this still does not solve your problem, then post back with the details.



                  • 6. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
                    John smith Newbie

                    the bean definition that i'm using :

                    Hello1Bean class:


                    @Stateless
                    public class Hello1Bean implements Hello1 {

                    @IgnoreDependency
                    @EJB(name="ejb/Hello2Local")
                    private Hello2Local hello;

                    }


                    Hello2LocalBean Class :


                    @Stateless
                    public class Hello2LocalBean implements Hello2Local {

                    @IgnoreDependency
                    @EJB(name="ejb/Hello1")
                    private Hello1 hello;

                    }


                    Hello2Bean Class :


                    @Stateless
                    public class Hello2Bean implements Hello2Local {

                    @IgnoreDependency
                    @EJB(name="ejb/Hello1")
                    private Hello1 hello;

                    }

                    we say that the interface Hello2Local has two implementations : Hello2LocalBean and Hello2Bean, and in this case, the entire exception stackrace is :

                    10:43:24,090 WARN [ServiceController] Problem starting service jboss.j2ee:jar=cyclic.jar,name=Hello1Bean,service=EJB3
                    java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container Hello1Bean: reference class: Hello2Local ejbLink: duplicated in cyclic.jar
                    at org.jboss.injection.EjbEncInjector.inject(EjbEncInjector.java:88)
                    at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:566)
                    at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:154)
                    at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:102)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
                    at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                    at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                    at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                    at $Proxy0.start(Unknown Source)
                    at org.jboss.system.ServiceController.start(ServiceController.java:417)
                    at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                    at $Proxy101.start(Unknown Source)
                    at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:120)
                    at org.jboss.ejb3.Ejb3Deployment.registerEJBContainer(Ejb3Deployment.java:301)
                    at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:362)
                    at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
                    at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                    at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                    at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                    at $Proxy0.start(Unknown Source)
                    at org.jboss.system.ServiceController.start(ServiceController.java:417)
                    at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                    at $Proxy33.start(Unknown Source)
                    at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:512)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                    at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                    at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                    at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
                    at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
                    at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
                    at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
                    at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
                    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:659)
                    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                    at $Proxy34.start(Unknown Source)
                    at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                    at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                    at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                    at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                    at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                    at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                    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:659)
                    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                    at $Proxy9.deploy(Unknown Source)
                    at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
                    at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
                    at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
                    at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
                    at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
                    10:43:24,090 INFO [EJB3Deployer] Deployed: file:/C:/Program Files/jboss-4.2.2.GA/jboss-4.2.2.GA/server/default/deploy/cyclic.jar
                    10:43:24,090 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

                    --- MBeans waiting for other MBeans ---
                    ObjectName: jboss.j2ee:jar=cyclic.jar,name=Hello1Bean,service=EJB3
                    State: FAILED
                    Reason: java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container Hello1Bean: reference class: com.gemalto.api.session.Hello2Local ejbLink: duplicated in cyclic.jar

                    --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
                    ObjectName: jboss.j2ee:jar=cyclic.jar,name=Hello1Bean,service=EJB3
                    State: FAILED
                    Reason: java.lang.RuntimeException: could not resolve global JNDI name for @EJB for container Hello1Bean: reference class: com.gemalto.api.session.Hello2Local ejbLink: duplicated in cyclic.jar

                    Thank's

                    • 7. Re: Cyclic dependency in EJB3 not resolved by JIRA EJBTHREE-
                      John smith Newbie


                      I tried your suggestion, and I think it works quite well.

                      Thank you.