Bean-call-bean problem


EJB programming & troubleshooting: Bean-call-bean problem

  1. Bean-call-bean problem (1 messages)

    Hi, I am using Inprise Application Server to do an EJB related project. I have a problem to lookup a bean from another bean. For example, I have two stateless beans, ABean and BBean. BBean returns a string "Hello" to who ever calls it. ABean lookup BBean and get that string and then return the string to ABean's caller. But, when my client calls ABean, client gets nothing. If client calls BBean, it gets the string. I use the following statements in ABean to lookup (get reference) BBean:
      Context ctx = new InitialContext();
      Object ref = ctx.lookup("bbeanhomename");
      BBeanHome home = (BBeanHome)javax.rmi.PortableRemoteObject
                   .narrow(ref, BBeanHome.class);
      BBean b = home.creat();

      Also, I tried another way to lookup BBean by using statement:
      Object ref = ctx.lookup("java:comp/env/ejb/BBeanHome");
    and this one doesn't work also. From Inprise's documentation, it says that if I want to use this one, I have to set the property "java.naming.factory.url.pkgs = com.inprise.j2ee". But where and how?
      Thank you for your help.
      Happy Christmas and Happy New Year.

      Di He
  2. Bean-call-bean problem[ Go to top ]

    This problem is well described, both in the EJB spec, and in the IAS documentation anf newsgroup.
    When looking up a bean from another bean, you should use the second method you describe:

    Object ref = ctx.lookup("java:comp/env/ejb/BBeanHome");

    But to do that, you need to include the "ejb/BBeanHome" key in the environment of the ABean. To do that, you should put both beans in the same jar and setup an ejb-reference (preferrably an ejb-link) to BBean in ABean. This is very easily done by using th DDEditor.
    Please check the examples coming with IAS also (ex: the school or pigs examples).