2 Replies Latest reply on Sep 9, 2004 7:14 PM by Leandro Terra Melo

    Locating EJBs from POJOs in the COMP enviroment

    Leandro Terra Melo Newbie

      i recently sent a post about JNDI issues, this post is not the same as the other one altough it's about the same topic. I found out the problem on the other post!!

      My question is pretty simple. After i spent some hours trying to figure out the problem in my application, i need some more answers.

      In a situation the i have a Façade -> POJO -> CMP, in other words, a situation where the façade delegates the business implementation to a POJO, what are the diferent manners this POJO can access the CMPs???

      So far, i found out 2 diferent ways, but in some of this methods i need some explanation

      First option - If i set a reference (in ejb-jar.xml and jboss.xml) for SessionOneBean to CMPOneBean, i can access CMPOneBean from the POJO with a lookup such that.


      Well, this is clear to me, i understand fine.

      Second option - If i DON'T set a reference (in ejb-jar.xml and jboss.xml) for SessionOneBean to CMPOneBean, i can access CMPOneBean from the POJO with a lookup such that.


      Why exactly does it work???? I don't get it!!!
      If i try the lookup wit the "java:comp/env/...." stuff it doesn't work in this case.

      Third option - If i just i don't set references and also lookup for the remote interface withoud the "java:comp/env/ejb/..." sutff it also works.


      Finally, why when i use the "java:comp/env/ejb/..." stuff, i cannot locate ejbs from POJOs??? Is it because the COMP enviroment is not accesible to POJOs???

        • 1. Re: Locating EJBs from POJOs in the COMP enviroment
          Darran Lofthouse Master

          As I said earlier forget about the POJOs, if your session bean calls code in a Java class then the code is executed as if the code has been typed in the method of the session bean.

          POJO is a buzzword that is used all over the place when talking about persistence and aspect oriented programming but when you are running within the container it is irrelevent for JNDI lookups.

          The 'java:' namespace in JNDI is an area that holds references to items only available from within the application server.

          The 'java:comp' namespace is for a specific component, each EJB will have its own. The only way to get items into this namespace is by adding <ejb-ref> and <ejb-local-ref> elements to the deployment descritptors.

          Names without the prefixes are in the global namespace, this is accessible from within the app server and from the outside. All components are automatically bound to the global namespace unless you configure otherwise.

          Q - Why does the following work?


          A - Because the component is bound to the global namespace on deployment.

          I am not sure if I understand your last question, when looking at the code performing lookups it is either running within a component deployed within the app server or it is a stand alone application running in its own JVM instance outside the application server.

          To see what is bound to JNDI: -

          Open http://localhost:8080/jmx-console
          Click on 'JNDI View'
          Click on the button for the 'list' operation

          The page that is displayed next shows you what is currently bound to the different namespaces.