issue with invoking a cmp bean from another cmp bean using JNDI

Discussions

EJB programming & troubleshooting: issue with invoking a cmp bean from another cmp bean using JNDI

  1. I have a cmp BeanA that invokes another cmp BeanB, so I am using a jndi lookup in BeanA to download the localhome object to BeanB using the following:

    Context ctx = new InitialContext();
    home = (LocalAddressHome) ctx.lookup("java:comp/env/ejb/BeanBHomeRef");

    then I specify the ejb/BeanBHomeRef, entity bean, local, BeanB's local home and component interface in EJB ref. when I am packaging BeanA
    I also package BeanB in a separate jar file.

    When I attempt to deploy the application it throws strange exception that says the folowing:
    --------------------------------------
    java.lang.IllegalArgumentException: BeanBEJB says it links to an ejb called BeanBEJB of local home class LocalBeanBHome but no bean with this local home c
    lassname and type can be found in this ejb-jar.
    -------------------------------------------
    yet when I un-jar the package, these class files exitsts.

    When I go ahead and delete the reference to BeanB from the BeanA package file, I am able to deploy the application but then correctly fails on jndi lookup.

    I have been able to open the cmpcustomer.ear sample application that comes with RI and execute it without any problem. But when I to package the same beans for example CustomerBean and it won't even allow me to create the customer.jar file. I get a screen full of errors.......

    I am using Sun RI 1.3.01, is there a known bug that I am not aware of? Is there a fix around it?
    Is there any another way to get the home ref. to BeanB so I can invoke create() method?
    Any advice or suggestions?
    thanksl
    -kaisaab
    kaisaab at yahoo dot com
  2. Hi kaisaab
      Can u send me your EJB files with xml's descriptors?
      Which server u are using?

    Arun Sethia
    sethia_jain at yahoo dot com
      
  3. Arun,
      Thanks for your response. It is fairly simple CMP application. I have a cJava client that invokes a StudentEJB(with remote interface) and calls create(args), which creats a student bean instance in the process attempts to create an address entity bean(local inteface).
      I use jndi lookup to download the ejb/AddressHomeRef so I can invoke addrHome.create(args) of AddressEJB, in the ejbPostCreate(arg) of the StudentEJB.
    Here's the deployment descriptor:
    --------------------------

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

    <ejb-jar>
      <display-name>Wed1JAR</display-name>
      <enterprise-beans>
        <entity>
          <display-name>AddressBean</display-name>
          <ejb-name>AddressBean</ejb-name>
          <local-home>j2eebootcamp.developingEJB.chapter10.address.LocalAddressHome</local-home>
          <local>j2eebootcamp.developingEJB.chapter10.address.LocalAddress</local>
          <ejb-class>j2eebootcamp.developingEJB.chapter10.address.AddressBean</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.String</prim-key-class>
          <reentrant>False</reentrant>
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Address</abstract-schema-name>
          <cmp-field>
            <description>no description</description>
            <field-name>addressID</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>zip</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>state</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>city</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>street</field-name>
          </cmp-field>
          <primkey-field>addressID</primkey-field>
          <security-identity>
            <description></description>
            <use-caller-identity></use-caller-identity>
          </security-identity>
        </entity>
        <entity>
          <display-name>StudentBean</display-name>
          <ejb-name>StudentBean</ejb-name>
          <home>j2eebootcamp.developingEJB.chapter10.student.StudentHome</home>
          <remote>j2eebootcamp.developingEJB.chapter10.student.Student</remote>
          <ejb-class>j2eebootcamp.developingEJB.chapter10.student.StudentBean</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.String</prim-key-class>
          <reentrant>False</reentrant>
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Student</abstract-schema-name>
          <cmp-field>
            <description>no description</description>
            <field-name>studentID</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>lastName</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>firstName</field-name>
          </cmp-field>
          <primkey-field>studentID</primkey-field>
          <ejb-local-ref>
            <ejb-ref-name>ejb/AddressHomeRef</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <local-home>LocalAddressHome</local-home>
            <local>LocalAddress</local>
            <ejb-link>AddressBean</ejb-link>
          </ejb-local-ref>
          <security-identity>
            <description></description>
            <use-caller-identity></use-caller-identity>
          </security-identity>
          <query>
            <description></description>
            <query-method>
              <method-name>findAllStudents</method-name>
              <method-params />
            </query-method>
            <ejb-ql>SELECT OBJECT(s) FROM Student AS s</ejb-ql>
          </query>
        </entity>
      </enterprise-beans>
      <relationships>
        <ejb-relation>
          <ejb-relation-name></ejb-relation-name>
          <ejb-relationship-role>
            <ejb-relationship-role-name>StudentBean</ejb-relationship-role-name>
            <multiplicity>One</multiplicity>
            <relationship-role-source>
              <ejb-name>StudentBean</ejb-name>
            </relationship-role-source>
            <cmr-field>
              <cmr-field-name>homeAddress</cmr-field-name>
            </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
            <ejb-relationship-role-name>AddressBean</ejb-relationship-role-name>
            <multiplicity>One</multiplicity>
            <cascade-delete />
            <relationship-role-source>
              <ejb-name>AddressBean</ejb-name>
            </relationship-role-source>
          </ejb-relationship-role>
        </ejb-relation>
      </relationships>
    </ejb-jar>
    ------------------------

      When I package the StudentEJB, it indicate the EJB ref. and the Sun's J2SDKEE 1.3 Ref. Implementation throws exception with following error at deployment time:
    ------------- at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadP
    ool.java:99)
    java.lang.IllegalArgumentException: AddressBean says it links to an ejb called A
    ddressBean of local home class LocalAddressHome but no bean with this local home
     classname and type can be found in this ejb-jar.
    -------------------------------------

    thanks!
  4. You have to adapt your ejb-jar.xml deployment descriptor to also include the references of Bean B. That is what it says in the exception message!
    So define BOTH BeanA and BeanB in your XML descriptor in BeanA's package.

    Jeroen
  5. thanks Jeroen,
      I just cheked and both of them does exist in the xml file(included) and I also checked the jar file and the class file does exist. I believe the error must not be accurate...
    ----------------------------------

      Thanks for your response. It is fairly simple CMP application. I have a cJava client that invokes a StudentEJB(with remote interface) and calls create(args), which creats a student bean instance in the process attempts to create an address entity bean(local inteface).
      I use jndi lookup to download the ejb/AddressHomeRef so I can invoke addrHome.create(args) of AddressEJB, in the ejbPostCreate(arg) of the StudentEJB.
    Here's the deployment descriptor:
    --------------------------

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

    <ejb-jar>
      <display-name>Wed1JAR</display-name>
      <enterprise-beans>
        <entity>
          <display-name>AddressBean</display-name>
          <ejb-name>AddressBean</ejb-name>
          <local-home>j2eebootcamp.developingEJB.chapter10.address.LocalAddressHome</local-home>
          <local>j2eebootcamp.developingEJB.chapter10.address.LocalAddress</local>
          <ejb-class>j2eebootcamp.developingEJB.chapter10.address.AddressBean</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.String</prim-key-class>
          <reentrant>False</reentrant>
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Address</abstract-schema-name>
          <cmp-field>
            <description>no description</description>
            <field-name>addressID</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>zip</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>state</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>city</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>street</field-name>
          </cmp-field>
          <primkey-field>addressID</primkey-field>
          <security-identity>
            <description></description>
            <use-caller-identity></use-caller-identity>
          </security-identity>
        </entity>
        <entity>
          <display-name>StudentBean</display-name>
          <ejb-name>StudentBean</ejb-name>
          <home>j2eebootcamp.developingEJB.chapter10.student.StudentHome</home>
          <remote>j2eebootcamp.developingEJB.chapter10.student.Student</remote>
          <ejb-class>j2eebootcamp.developingEJB.chapter10.student.StudentBean</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.String</prim-key-class>
          <reentrant>False</reentrant>
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>Student</abstract-schema-name>
          <cmp-field>
            <description>no description</description>
            <field-name>studentID</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>lastName</field-name>
          </cmp-field>
          <cmp-field>
            <description>no description</description>
            <field-name>firstName</field-name>
          </cmp-field>
          <primkey-field>studentID</primkey-field>
          <ejb-local-ref>
            <ejb-ref-name>ejb/AddressHomeRef</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <local-home>LocalAddressHome</local-home>
            <local>LocalAddress</local>
            <ejb-link>AddressBean</ejb-link>
          </ejb-local-ref>
          <security-identity>
            <description></description>
            <use-caller-identity></use-caller-identity>
          </security-identity>
          <query>
            <description></description>
            <query-method>
              <method-name>findAllStudents</method-name>
              <method-params />
            </query-method>
            <ejb-ql>SELECT OBJECT(s) FROM Student AS s</ejb-ql>
          </query>
        </entity>
      </enterprise-beans>
      <relationships>
        <ejb-relation>
          <ejb-relation-name></ejb-relation-name>
          <ejb-relationship-role>
            <ejb-relationship-role-name>StudentBean</ejb-relationship-role-name>
            <multiplicity>One</multiplicity>
            <relationship-role-source>
              <ejb-name>StudentBean</ejb-name>
            </relationship-role-source>
            <cmr-field>
              <cmr-field-name>homeAddress</cmr-field-name>
            </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
            <ejb-relationship-role-name>AddressBean</ejb-relationship-role-name>
            <multiplicity>One</multiplicity>
            <cascade-delete />
            <relationship-role-source>
              <ejb-name>AddressBean</ejb-name>
            </relationship-role-source>
          </ejb-relationship-role>
        </ejb-relation>
      </relationships>
    </ejb-jar>
    ------------------------

      When I package the StudentEJB, it indicate the EJB ref. and the Sun's J2SDKEE 1.3 Ref. Implementation throws exception with following error at deployment time:
    ------------- at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadP
    ool.java:99)
    java.lang.IllegalArgumentException: AddressBean says it links to an ejb called A
    ddressBean of local home class LocalAddressHome but no bean with this local home
     classname and type can be found in this ejb-jar.
    -------------------------------------

    thanks
  6. Try using FQCN = FUlly Qualified Class Names in your ejb-local-ref part of the XML descriptor. I think that should fix your problems.
    It should look something like:
    <ejb-local-ref>
      <ejb-ref-name>ejb/AddressHomeRef</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>j2eebootcamp.developingEJB.chapter10.address.LocalAddressHome</local-home>
      <local>j2eebootcamp.developingEJB.chapter10.address.LocalAddress</local>
      <ejb-link>AddressBean</ejb-link>
    </ejb-local-ref>

    This should probably fix it. If that doesn't work, I think I can remember that there are some problems with Local interfaces and different JAR files. But I don't know for sure. Else try packaging it all in 1 JAR and see if that works. If it does, then your descriptors etc. are not to blame. Let me know if it works (or not)

    Jeroen