2 Replies Latest reply on Aug 11, 2006 8:48 PM by Peter Johnson

    could not dereference object

    Koh Chong Ming Newbie

      Hi,
      I'm using jboss4.0.3. I want to reference my jsp page to EJB but get a "could not dereference object" upon running the jsp with this as it went into the catch exception instead of looking up to the EJB:

      try {
       Context initial = new InitialContext();
       Object objref = initial.lookup("java:comp/env/ejb/EJBMusic");
       System.out.println("lookup success for ejb/EJBMusic");
       // a reference to the home interface is shareable
       musicHome = (MusicIteratorHome)PortableRemoteObject.narrow(objref, MusicIteratorHome.class);
       System.out.println("created MusicIteratorHome object");
      
       objref = initial.lookup("java:comp/env/ejb/MyMusicCart");
       System.out.println("lookup success for ejb/MyMusicCart");
       // a reference to the home interface is shareable
       cartHome = (MusicCartHome)PortableRemoteObject.narrow(objref, MusicCartHome.class);
       System.out.println("created MusicCartHome object");
      
       } catch (Exception ex) {
       System.out.println("Unexpected Exception: " +ex.getMessage());


      My web.xml
      <ejb-ref>
       <ejb-ref-name>ejb/EJBMusic</ejb-ref-name>
       <ejb-ref-type>Session</ejb-ref-type>
       <home>asg.MusicEJB.MusicIteratorHome</home>
       <remote>asg.MusicEJB.MusicIterator</remote>
       <ejb-link>ejb-jar-iterator.jar#MusicIteratorBean</ejb-link>
      </ejb-ref>
      
       <ejb-ref>
       <ejb-ref-name>ejb/MyMusicCart</ejb-ref-name>
       <ejb-ref-type>Session</ejb-ref-type>
       <home>asg.MusicCartEJB.MusicCartHome</home>
       <remote>asg.MusicCartEJB.MusicCart</remote>
       <ejb-link>ejb-jar-ic.jar#MusicCartBean</ejb-link>
      
       </ejb-ref>

      I did not include any jboss-web.xml or jboss.xml. Is it i need to include them before it can work? Please help, i have been solving this problem for days

        • 1. Re: could not dereference object
          Koh Chong Ming Newbie

           

          "vitalstrike82" wrote:
          Hi,
          I'm using jboss4.0.3. I want to reference my jsp page to EJB but get a "could not dereference object" upon running the jsp with this as it went into the catch exception instead of looking up to the EJB:

          try {
          
           objref = initial.lookup("java:comp/env/ejb/MyMusicCart");
           System.out.println("lookup success for ejb/MyMusicCart");
           // a reference to the home interface is shareable
           cartHome = (MusicCartHome)PortableRemoteObject.narrow(objref, MusicCartHome.class);
           System.out.println("created MusicCartHome object");
          
           } catch (Exception ex) {
           System.out.println("Unexpected Exception: " +ex.getMessage());


          My web.xml
          [code
          <ejb-ref>
          <ejb-ref-name>ejb/MyMusicCart</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <home>asg.MusicCartEJB.MusicCartHome</home>
          <remote>asg.MusicCartEJB.MusicCart</remote>
          <ejb-link>ejb-jar-ic.jar#MusicCartBean</ejb-link>

          </ejb-ref>


          • 2. Re: could not dereference object
            Peter Johnson Master

            I have never used the syntax you used for the ejb-link node in your web.xml file. In my web.xml file, I always set ejb-link to the same text as ejb-ref-name. So what I am advising might not work exactly as I say.

            Try adding a jboss-web.xml file with the following:

            <jboss-web>
             <ejb-ref>
             <ejb-ref-name>ejb/EJBMusic</ejb-ref-name>
             <jndi-name>ejb/EJBMusic</jndi-name>
             </ejb-ref>
             <ejb-ref>
             <ejb-ref-name>ejb/EJBMusicCart</ejb-ref-name>
             <jndi-name>ejb/EJBMusicCart</jndi-name>
             </ejb-ref>
            </jboss-web>