4 Replies Latest reply on Nov 13, 2002 2:19 PM by joeflux

    Exception calling EJB from EJB

    joeflux

      Hi,

      I am trying to call a Session bean from an Entity bean as shown in the code:

      Context lContext = new InitialContext();
      Object homeObject = lContext.lookup("SequenceGenerator");

      SequenceGeneratorHome lHome = (SequenceGeneratorHome)
      PortableRemoteObject.narrow(homeObject,SequenceGeneratorHome.class);
      SequenceGenerator lBean = (SequenceGenerator) PortableRemoteObject.narrow(lHome.create(),SequenceGenerator.class);

      the above code throws a lookup failure NamingException
      I try the code below and with no difference:

      SequenceGeneratorHome lHome = (SequenceGeneratorHome) lContext.lookup("java:comp/env/ejb/testone/SequenceGenerator");
      SequenceGenerator lBean = (SequenceGenerator) lHome.create();

      Is there any different way of calling an EJB from with in an EJB??

      thanks.

        • 1. Re: Exception calling EJB from EJB
          summun

          You only must to find through JNDI the home object. Once you have it, you can directly call the create method of the home to obtain the remote interface:

          Context lContext = new InitialContext();
          Object homeObject = lContext.lookup("SequenceGenerator");

          SequenceGeneratorHome lHome = (SequenceGeneratorHome)
          PortableRemoteObject.narrow(homeObject,SequenceGeneratorHome.class);
          SequenceGenerator lBean = lHome.create();

          • 2. Re: Exception calling EJB from EJB
            joeflux

            Still unable to call EJB from EJB. Please find attached the source file. Any help in this regard will be greatly appriciated.

            Thanks again.

            • 3. Re: Exception calling EJB from EJB
              joeflux

              Still unable to call EJB from EJB. Please find attached the source file. Any help in this regard will be greatly appriciated.

              Thanks again.

              • 4. Re: Exception calling EJB from EJB
                joeflux

                Still unable to call EJB from EJB. Please find attached the source file. Any help in this regard will be greatly appriciated.

                Thanks again.