3 Replies Latest reply on Jan 26, 2006 1:19 PM by Phil Clark

    2 EJBs, implmented same way, only one can be accessed

    Phil Clark Newbie

      Is the issue with the Application Server?

      I have two EJB's, MemberBean and PersonBean, implemented the same way. However, jndi lookup is successful for one (MemberBean), but not the other (PersonBean - javax.naming.NameNotFoundException on the second lookup). See below for the detail, I don't get this one:

      From the log file you can see that both beans are bound succesfully

      APPSERVER LOG FILE

      16:09:34,183 INFO [EjbModule] Deploying MemberBean
      16:09:34,208 INFO [EjbModule] Deploying PersonBean
      16:09:36,917 INFO [BaseLocalProxyFactory] Bound EJB LocalHome 'MemberBean' to jndi 'MemberBeanLocalHome'
      16:09:37,066 INFO [BaseLocalProxyFactory] Bound EJB LocalHome 'PersonBean' to jndi 'PersonBeanLocalHome'
      ...
      ##However the PersonBean fails the context lookup ##

      16:10:22,630 ERROR [PersonDelegate] javax.naming.NameNotFoundException: PersonBeanLocalHome not bound
      ...
      2006-01-24 16:10:22,368 DEBUG [org.blah.delegate.MemberDelegate] GOT MEMBER EJB
      ...
      2006-01-24 16:10:22,629 DEBUG [org.blah.delegate.PersonDelegate] ENTERED>>>>>>>>>>>>>>>>>>>>>
      2006-01-24 16:10:22,630 ERROR [org.blah.delegate.PersonDelegate] javax.naming.NameNotFoundException: PersonBeanLocalHome not bound

      Both Beans are found in the jndi view

      JMX-Console

      +- PersonBeanLocalHome (proxy: $Proxy105 implements interface org.blah.ejb.PersonBeanLocalHome)
      +- XAConnectionFactory
      +- UserTransaction
      +- MemberBeanLocalHome (proxy: $Proxy104 implements interface org.blah.ejb.MemberBeanLocalHome)

      Implmentation Snippets

      PersonBean lookup:

      
       private PersonBeanLocal getLocalSession()
       {
       PersonBeanLocal local = null;
      
       try
       {
       logger.debug("ENTERED>>>>>>>>>>>>>>>>>>>>>");
      
       Context ctx = new InitialContext();
       Object ref = ctx.lookup("java:comp/env/PersonBeanLocalHome");
      
       logger.debug("GOT PERSON EJB");
       logger.debug("Object ::: " + ref.getClass().getName());
      
       PersonBeanLocalHome home = (PersonBeanLocalHome)ref;
       local = home.create();
       }
       catch(Exception e)
       {
       logger.error("" + e.toString());
       }
       return local;
       }
      
      


      MemberBean lookup:

      
       private MemberBeanLocal getLocalSession()
       {
       MemberBeanLocal local = null;
      
       try
       {
       Context ctx = new InitialContext();
       Object ref = ctx.lookup("java:comp/env/MemberBeanLocalHome");
      
       logger.debug("GOT MEMBER EJB");
       logger.debug("Object ::: " + ref.getClass().getName());
      
       MemberBeanLocalHome home = (MemberBeanLocalHome)ref;
       local = home.create();
       }
       catch(Exception e)
       {
       logger.error("" + e.toString());
       }
       return local;
       }
      
      


      DESCRIPTORS
      
      ejb-jar.xml
      
      ...
      <ejb-jar>
      
       <enterprise-beans>
       <session>
       <display-name>MemberBean</display-name>
       <ejb-name>MemberBean</ejb-name>
       <local-home>org.blah.ejb.MemberBeanLocalHome</local-home>
       <local>org.blah.ejb.MemberBeanLocal</local>
       <ejb-class>org.blah.ejb.MemberBeanLocalEJB</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       </session>
       <session>
       <display-name>PersonBean</display-name>
       <ejb-name>PersonBean</ejb-name>
       <local-home>org.blah.ejb.PersonBeanLocalHome</local-home>
       <local>org.blah.ejb.PersonBeanLocal</local>
       <ejb-class>org.blah.ejb.PersonBeanLocalEJB</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       </session>
       <assembly-descriptor>
       </assembly-descriptor>
       </enterprise-beans>
      </ejb-jar>
      ...
      
      
      jboss.xml
      
       <jboss>
       <enterprise-beans>
       <session>
       <ejb-name>MemberBean</ejb-name>
       <local-jndi-name>MemberBeanLocalHome</local-jndi-name>
       </session>
       <session>
       <ejb-name>PersonBean</ejb-name>
       <local-jndi-name>PersonBeanLocalHome</local-jndi-name>
       </session>
       <secure>false</secure>
       </enterprise-beans>
       </jboss>
      


      Using JBoss 4.0.3 SP1

        • 1. Re: 2 EJBs, implmented same way, only one can be accessed
          Phil Clark Newbie

          Crud, found it, user error of course. It was a long day when I configured the second bean. I forgot to add the ejb-ref/link entry for the failing bean in the tomcat web-xml. All is good now.

          • 2. Re: 2 EJBs, implmented same way, only one can be accessed
            tony anecito Novice

            Hi Phil,

            I am having the same issue. Can you please eloborate about the tomcat web-xml? What file specifically how and why?

            Thanks,
            -Tony

            • 3. Re: 2 EJBs, implmented same way, only one can be accessed
              Phil Clark Newbie

              Tony,

              I am using struts and ejb in my application. I am using the JBoss bundled tomcat servlet container. Tomcat has its own JNDI resource (separate from JBoss JNDI). I had to create a reference / link in my webapp for each of my ejbs deployed/managed by JBoss. Below is an example of the web.xml file related to my other post / descriptors (note the ejb's are "local" not remote).

              Hopefully this helps.

              ../WEB-INF/web.xml

              <web-app>
               <servlet>
               ...
               </servlet>
               <servlet-mapping>
               ...
               </servlet-mapping>
               <welcome-file-list>
               ...
               </welcome-file-list>
              
               <!-- EJB References -->
               <ejb-local-ref>
               <ejb-ref-name>PersonBeanLocalHome</ejb-ref-name>
               <ejb-ref-type>Session</ejb-ref-type>
               <local-home>org.blah.ejb.PersonBeanLocalHome</local-home>
               <local>org.blah.ejb.PersonBeanLocal</local>
               <ejb-link>PersonBean</ejb-link>
               </ejb-local-ref>
               <ejb-local-ref>
               <ejb-ref-name>MemberBeanLocalHome</ejb-ref-name>
               <ejb-ref-type>Session</ejb-ref-type>
               <local-home>org.blah.ejb.MemberBeanLocalHome</local-home>
               <local>org.blah.ejb.MemberBeanLocal</local>
               <ejb-link>MemberBean</ejb-link>
               </ejb-local-ref>
              </web-app>