2 Replies Latest reply on Sep 24, 2002 1:08 AM by dmaclaren

    ejb-local-ref

    squat

      I have 2 EJBs - one CMP and one session. The ejb-jar.xml looks like:

      <?xml version="1.0"?>

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

      <display-name>UniqGenBean</display-name>
      <ejb-name>squat/masterpizz/orderapp/uniqGenBean</ejb-name>
      squat.ejbs.entity.uniqGenHome
      squat.ejbs.entity.uniqGen
      <local-home>squat.ejbs.entity.uniqGenLocalHome</local-home>
      squat.ejbs.entity.uniqGenLocal
      <ejb-class>squat.ejbs.entity.uniqGenBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>squat.ejbs.entity.uniqGenPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>uniqGenBean</abstract-schema-name>
      <cmp-field>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>beanName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>counter</field-name>
      </cmp-field>

      <query-method>
      <method-name>findByBeanName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[SELECT OBJECT(b) FROM uniqGenBean AS b WHERE b.beanName = ?1]]></ejb-ql>




      <ejb-name>squat/masterpizz/orderapp/uqGenBean</ejb-name>
      squat.ejbs.session.uqGenHome
      squat.ejbs.session.uqGen
      <local-home>squat.ejbs.session.uqGenLocalHome</local-home>
      squat.ejbs.session.uqGenLocal
      <ejb-class>squat.ejbs.session.uqGenBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Container</transaction-type>
      <ejb-local-ref>
      <ejb-ref-name>squat/masterpizz/orderapp/uniqGenBeanLnk</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>squat.ejbs.entity.uniqGenLocalHome</local-home>
      squat.ejbs.entity.uniqGenLocal
      <ejb-link>squat/masterpizz/orderapp/uniqGenBean</ejb-link>
      </ejb-local-ref>

      </enterprise-beans>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>squat/masterpizz/orderapp/usersBean</ejb-name>
      <method-name>*</method-name>


      <ejb-name>squat/masterpizz/orderapp/uniqGenBean</ejb-name>
      <method-name>*</method-name>


      <ejb-name>squat/masterpizz/orderapp/uqGenBean</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      So you see i have ejb-local-ref - and it's name is
      squat/masterpizz/orderapp/uniqGenBeanLnk

      But in session ejb i want to lookup like this

      InitialContext Context = new InitialContext();
      System.out.println("[uqGenBean.ejbCreate -> Got context]");
      ref = Context.lookup("squat/masterpizz/orderapp/uniqGenBeanLnk");
      System.out.println("[uqGenBean.ejbCreate -> Lookup uniqGenBean]");

      And i get error - NameNotFoundException: uniqGenBeanLnk

      But if i lookup

      java:comp/env/squat/masterpizz/orderapp/uniqGenBeanLnk

      everything is ok.

      The question is: what reason of using ejb-local-ref if i cannot lookup it by simple way without using java:comp/env

      ?!

        • 1. Re: ejb-local-ref
          dmaclaren

          You may not fully understand the reason behind the localref. This is here to not invoke the RMI network calls that you get from the normal calls. The Jndi naming is just the lookup. The Jboss deploys the name into the JNDI namespace. The naming of java:/comp/env is the why to organize the objects respectively.

          The feature that is awarded is you do not get hit with the networking call.

          • 2. Re: ejb-local-ref
            dmaclaren

            Now, if you are on the machine that the beans are, you do a jndi lookup using "local/ejbname".