5 Replies Latest reply on Mar 22, 2002 8:28 PM by Adrian Brock

    JNDI problem with local bean

    Alice Newbie

      My EmployeeBean has a 1-to-many r with AddressBean (AddressBean has only a local interface). Both are CMP entity beans. In one of my EmployeeBean methods I am looking up for AddressLocalHome but I get an exception javax.naming.NameNotFoundException "Add not bound". They both are defined in a single ejb-jar so I guess I don't need a jboss.xml. But I also tried it with jboss.xml providing a different jndi name but doesn't seem to help. I have included my ejb-jar.xml and jboss.xml with only relevant parts. Please help !!

      Thanks a lot.

      In a EmployeeBean's method:
      AddressLocalHome home = (AddressLocalHome)jndiContext.lookup("ejb/Add"); // doesn't work with proj1/Add either

      AddressLocal add_1 = home.create("anything");

      ejb-jar.xml


      <ejb-name>EmployeeBean</ejb-name>

      <ejb-local-ref>
      <ejb-ref-name>ejb/Add</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>alice.proj1.AddressLocalHome</local-home>
      alice.proj1.AddressLocal
      <ejb-link>AddressBean</ejb-link>
      </ejb-local-ref>




      <ejb-name>AddressBean</ejb-name>


      jboss.xml:


      <ejb-name>EmployeeBean</ejb-name>
      <jndi-name>proj1/Emp</jndi-name>
      <ejb-ref>
      <ejb-ref-name>ejb/Add</ejb-ref-name>
      <jndi-name>proj1/Add</jndi-name>
      </ejb-ref>
      <configuration-name></configuration-name>



      <ejb-name>AddressBean</ejb-name>
      <jndi-name>proj1/Add</jndi-name>
      <configuration-name></configuration-name>

        • 1. Re: JNDI problem with local bean
          Adrian Brock Master

          I think you want something more like the following.
          Notice the order.
          Also you don't need <ejb-ref> in jboss.xml if you
          are using <ejb-link>

          ejb-jar.xml

          [pre]

          <ejb-name>AddressBean</ejb-name>



          <ejb-name>EmployeeBean</ejb-name>
          <ejb-local-ref>
          <ejb-ref-name>ejb/Add</ejb-ref-name>
          <ejb-ref-type>Entity</ejb-ref-type>
          <local-home>alice.proj1.AddressLocalHome</local-home>
          alice.proj1.AddressLocal
          <ejb-link>AddressBean</ejb-link>
          </ejb-local-ref>

          [/pre]
          jboss.xml:
          [pre]

          <ejb-name>AddressBean</ejb-name>
          <jndi-name>proj1/Add</jndi-name>
          <configuration-name></configuration-name>



          <ejb-name>EmployeeBean</ejb-name>
          <jndi-name>proj1/Emp</jndi-name>
          <configuration-name></configuration-name>

          [/pre]

          You generally don't need local with JBoss. It will
          use local automagically unless you turn the optimization
          off.
          Also, you might want to use "java:comp/env/ejb/Add"
          to make it obvious you are using an <ejb-ref>.

          Regards,
          Adrian

          • 2. Re: JNDI problem with local bean
            Alice Newbie

            Adrian, thanks for the help.

            I did exactly as u told. Before I didn't think order of was important. Anyway, the thing even didn't work for me after changing the order etc.

            Then I changed one more thing. In my EmployeeBean I changed my lookup call to:

            AddressLocalHome home = (AddressLocalHome)jndiContext.lookup("local/AddressBean);

            and it started working!! Didn't work with proj1/Add or ejb/Add. I am really confused about all this. Can someone please guide me where I can learn more about this jndi binding in JBoss and whats going on here??

            Thanks a lot.

            • 3. Re: JNDI problem with local bean
              Adrian Brock Master

              I normally post this link about once a week :-)

              http://www.jboss.org/online-manual/HTML/ch07s13.html

              local/AddressBean is the default binding for a local
              bean. You didn't specify the local jndi name.

              Did you try the java:comp/env/ejb/Add version?

              If you look back to early this week in this forum,
              there are some posts about ejb-refs and local bindings.
              They include links to some examples.

              Regards,
              Adrian

              • 4. Re: JNDI problem with local bean
                Alice Newbie

                Thank u very much. I had already read the section u reffered to but it didn't talk about local-jndi-name. Neither did it talk about "local".. So its difficult for a person like me to figure all of it w/o help..

                One more thing: Does the order of in ejb-jar matter? For example I declared EmployeeBean first that has a reference to AddressBean declared after it. It worked fine for me though ..

                Thanks again

                • 5. Re: JNDI problem with local bean
                  Adrian Brock Master

                  I don't think the order should matter.

                  I can't remember without looking at the code, but it
                  should create all the containers first and then link them.

                  Regards,
                  Adrian