2 Replies Latest reply on Jan 4, 2004 6:46 AM by Pawel Menich

    Problem with getting home object reference.

    Pawel Menich Newbie

      I have a problem with getting a home object reference. I use EJBHomeFactory, and in method lookUPHome() i specified short EJB home object class name. In Struts action code i wrote UserServicesHome home = (UserServicesHome) EJBHomeFactory.getFactory().lookUpHome(UserServicesHome.class); and in web.xml i put ejb-ref tag like this:

      <ejb-ref>
      <ejb-ref-name>net.menich.mypack.UserServicesHome</ejb-ref-name>
      <ejb-ref-type>
      Session
      </ejb-ref-type>

      net.menich.mypack.UserServicesHome


      net.menich.mypack.UserServices

      </ejb-ref>

      and in jboss-web.xml :

      <jboss-web>
      <context-root>/</context-root>
      <virtual-host>localhost</virtual-host>
      <ejb-ref>
      <ejb-ref-name>net.menich.mypack.UserServicesHome</ejb-ref-name>
      <jndi-name>ejb/UserServicesHome</jndi-name>
      </ejb-ref>
      </jboss-web>

      and in jboss.xml:


      <ejb-name>UserServicesEJB</ejb-name>
      <jndi-name>ejb/UserServicesHome</jndi-name>


      in ejb-jar.xml i have that fragment:




      <ejb-name>UserServicesEJB</ejb-name>

      net.menich.mysam.app.services.UserServicesEJBHome
      net.menich.mypack.UserServicesEJB
      <ejb-class>net.menich.mypack.UserServicesEJBSession</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>



      When I run my app i get NameNotFoundException: net.menich.mypack.UserServicesHome not bound.

      I have my EJBHomeFactory class in WEB-INF/class folder. War with client code and EJB's are pack into one EAR file.

      When i'm specified net.menich.mypack.UserServicesHome in element <jndi-name> in jboss.xml all is beautiful running.

      I don't know why i'm getting NameNotFounEception when i'm use web.xml re-tag and jboss-web.xml mapping.

      Thank's in advance.

      Regards, Pawel Menich

        • 1. Re: Problem with getting home object reference.
          Jon Barnett Master

          Maybe I'm a bit slow with this but it is not apparent from your description what the String is that you are using for the lookup - whatever you use in ctx.lookup("...").

          In any case, the error is the lookup cannot find any object by the name supplied in the string.

          In theory, you are using an indirection definition so the String should be:
          java:comp/env/net.menich.mypack.UserServicesHome

          The lookup string, net.menich.mypack.UserServicesHome would only work if your JNDI name was net.menich.mypack.UserServicesHome.

          • 2. Re: Problem with getting home object reference.
            Pawel Menich Newbie

            Thank's for help. In EJBHomeFactory method lookUpHome() i specified only home object class name e.g. lookUpHome(UserServicesHome.class).

            In my implementation EJBHomeFactory method lookUpHome i was having:

            public EJBHome lookUpHome(Class homeClass) {

            EJBHome anEJBHome;
            anEJBHome = (EJBHome) this.ejbHomes.get(homeClass);

            try {

            if(anEJBHome == null) {

            anEJBHome = (EJBHome) PortableRemoteObject.narrow(ctx.lookup(homeClass.getName()), homeClass);
            this.ejbHomes.put(homeClass, anEJBHome);
            }


            return anEJBHome;

            }

            when i deploy my ejb with FQ name like jndi-name, all was OK, but when i use ejb-ref tag in web.xml an jboss-web.xml, i getting NameNotFoundException. Problem was in EJBHomeFactory lookUpHome implementation. Correct form should look like this:

            public EJBHome lookUpHome(Class homeClass) throws HomeFactoryException {

            EJBHome anEJBHome;
            anEJBHome = (EJBHome) this.ejbHomes.get(homeClass);

            try {

            if(anEJBHome == null) {

            anEJBHome = (EJBHome) PortableRemoteObject.narrow(ctx.lookup("java:comp/env/" + homeClass.getName()), homeClass);
            this.ejbHomes.put(homeClass, anEJBHome);
            }

            } catch (ClassCastException e) {

            throw new HomeFactoryException(e);

            } catch (NamingException e) {

            throw new HomeFactoryException(e);

            }

            return anEJBHome;

            }

            In ctx.lookup I put jndi path java:name/comp/env/ and concat with homeClass.getName() result.

            Once again thank for pay attention to add java:comp/env/ jndi context.

            Regards Pawel Menich