12 Replies Latest reply on Dec 23, 2008 12:27 PM by green bean

    Possible Bug?

    green bean Newbie

      So, I have two different SLSB mapped to two different locations in JNDI:

      javaEEApplication/HelloWorldStatelessBean/remote-com.di.examples.HelloWorld - EJB3.x Remote Business Interface

      javaEEApplication/StatelessLifecycle/remote-com.di.examples.HelloWorld - EJB3.x Remote Business Interface

      As you can see, they share the same "Business Interface", yet the implementation classes are different.

      When I do a DI within a JSP using:
      <%!
      @EJB(name="javaEEApplication/HelloWorldStatelessBean/remote-com.di.examples.HelloWorld") HelloWorld helloWorld;
      @EJB(name="javaEEApplication/StatelessLifecycle/remote-com.di.examples.HelloWorld") HelloWorld lifecycle;
      %>

      The two references point to the same object.. I would assume each reference would point the correct implementation ...

      So, it seems to me like if two impls share the same interface, JBoss doesn't differentiate them?


        • 1. Re: Possible Bug?
          Andrew Rubinger Master

          @EJB.name is for the JNDI name of the reference within the ENC. Check your JNDI View, looking under the component (your EJB's deployment) namespace for the correct value.

          If you'd like to use the global JNDI name (as you are), use @EJB.mappedName.

          Or, designate the target EJB by its name: @EJB.beanName.

          S,
          ALR

          • 2. Re: Possible Bug?
            Andrew Rubinger Master

             

            "green_bean_1" wrote:
            So, it seems to me like if two impls share the same interface, JBoss doesn't differentiate them?


            If you can provide a use case (unit test) exhibiting this, we can open a JIRA for resolution. :)

            S,
            ALR

            • 3. Re: Possible Bug?
              jaikiran pai Master

              In addition to what Andrew said, which version of JBossAS do you use?

              • 4. Re: Possible Bug?
                Andrew Rubinger Master

                Judging from those JNDI Names, gotta be at least AS 5 CR2. :)

                S,
                ALR

                • 5. Re: Possible Bug?
                  green bean Newbie

                  As for my platform, I am using jboss-5.0.0.GA on OS X 10.5.6 using JDK 1.5.0_16..

                  In regards to the comments / questions dealing with the mappedName v. name.. the example yields the same results whether I am using mappedName or name. in other words..
                  @EJB(name="javaEEApplication/HelloWorldStatelessBean/remote-com.di.examples.HelloWorld") HelloWorld helloWorld;
                  @EJB(name="javaEEApplication/StatelessLifecycle/remote-com.di.examples.HelloWorld") HelloWorld lifecycle;
                  @EJB(name="HelloWorldStatelessBean") HelloWorld helloWorldBean;
                  @EJB(name="StatelessLifecycle") HelloWorld lifecycleBean;

                  all resolve to the same exact EJB even though HelloWorldStatelessBean and StatelessLifecyle are two different beans..


                  i have tried many variations.. but still no success. it still appears that jboss is making the assumption that a business interface can be implemented by only one EJB.. however, in my example i have two beans implement the same business interface. each ejb has a specific (and different) implementation..



                  • 6. Re: Possible Bug?
                    green bean Newbie

                    sorry.. the code should be:


                    @EJB(mappedName="javaEEApplication/HelloWorldStatelessBean/remote-com.di.examples.HelloWorld") HelloWorld helloWorld;
                    @EJB(mappedName="javaEEApplication/StatelessLifecycle/remote-com.di.examples.HelloWorld") HelloWorld lifecycle;
                    @EJB(name="HelloWorldStatelessBean") HelloWorld helloWorldBean;
                    @EJB(name="StatelessLifecycle") HelloWorld lifecycleBean;

                    • 7. Re: Possible Bug?
                      green bean Newbie

                      ok.. so.. i lied.. the @EJB(mappedName) variation works.. its just the @EJB(name=) variation that doesn't work..

                      in my ejb-jar.xml file there is an entry for the StatelessLifecycleBean but not for the HelloWorldStatelessBean.. s

                      • 8. Re: Possible Bug?
                        Andrew Rubinger Master

                        So you're still exhibiting unexpected behaviour?

                        Does @EJB.name work as expected (ie resolves properly to the ENC name)? I'd be surprised if it didn't as we're shipping a compliant implementation.

                        S,
                        ALR

                        • 9. Re: Possible Bug?
                          Mopuffus Lumpkins Newbie

                          hi,

                          IMHO here we deal here with two problems (at least), one of my first question is which is your goal ?
                          Here are my answers to your problem :
                          1.The EJBs does JNDI behind the scene and to solve this you must help him a little - with some configuration files.
                          2.If two bean are implementing the same interface (strategy which is not desirable) then you shod use the beanName attribute to inject the right bean.
                          In most of the cases you use the EJB without any attribute and let the container to do the look up job.
                          Why you use the @EJB together with the name ?


                          Regards,
                          M

                          • 10. Re: Possible Bug?
                            green bean Newbie


                            EJB.name does NOT work. it does NOT correctly "inject" the specific implementation.. How would I verify the ENC name for each specific implementation?



                            2.If two bean are implementing the same interface (strategy which is not desirable) then you shod use the beanName attribute to inject the right bean.


                            I am curious why this strategy is undesirable.. Seems like the purpose of OO. Single interface with multiple realizations..

                            • 11. Re: Possible Bug?
                              Andrew Rubinger Master

                               

                              "green_bean_1" wrote:
                              EJB.name does NOT work. it does NOT correctly "inject" the specific implementation.. How would I verify the ENC name for each specific implementation?


                              You haven't supplied the right ENC name yet, so how can you assert it doesn't work? :P.

                              Get the ENC Name using JNDIView in the JMX Console.

                              "mopuf" wrote:
                              2.If two bean are implementing the same interface (strategy which is not desirable)


                              The drawback is that the interface is no longer deterministic. It's a reach to infer this is bad practice, in fact, I think it promotes good design ie. separation of contract and impl.

                              S,
                              ALR

                              • 12. Re: Possible Bug?
                                green bean Newbie

                                So.. I think I have finally narrowed it down with the help of ALR and mopuf. props to you both.

                                it appears that if I annotate the beans with a specific @Stateless.name and use @EJB.beanName things work fine.

                                but, if i let the container use the default name (which I understand to be just the unqualified class name) in conjunction an explicit EJB.beanName the injection does not work properly..

                                does this make sense?