2 Replies Latest reply on Mar 16, 2008 3:41 PM by Youri adcsdc

    local entity bean lookup from session bean goes wrong

    Youri adcsdc Newbie

      I have an EJB21 session bean that uses an entity bean.

      This is located in the ejb-jar:

      <entity>
       <ejb-name>Book</ejb-name>
       <local-home>BookHome</local-home>
       <local>Book</local>
       <ejb-class>BookEntity</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>Book</abstract-schema-name>
       <cmp-field>
       <field-name>title</field-name>
       </cmp-field>
      
       <primkey-field>title</primkey-field>
      
      
       <ejb-local-ref>
       <ejb-ref-name>ejb/Book</ejb-ref-name>
       <ejb-ref-type>Entity</ejb-ref-type>
       <local-home>BookHome</local-home>
       <local>Book</local>
       <ejb-link>Book</ejb-link>
       </ejb-local-ref>
       </entity>
      


      JNDI:
      java:comp namespace of the Book bean:
      
       +- env (class: org.jnp.interfaces.NamingContext)
       | +- ejb (class: org.jnp.interfaces.NamingContext)
       | | +- Book[link -> local/Book@16126503] (class: javax.naming.LinkRef)
      


      But my lookup says:
      javax.naming.NameNotFoundException: ejb not bound


      This code is inside the session bean is as follow:
       try {
       InitialContext ic = new InitialContext();
      
       book = (BookHome) ic.lookup("java:comp/env/ejb/Book");
      
       } catch (NamingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      


      Any suggestions? I can't get the local entity bean to work with the session bean.

        • 1. Re: local entity bean lookup from session bean goes wrong
          jaikiran pai Master

          If you are trying to create a local ref for a entity bean inside a session bean, then this piece of code

           <ejb-local-ref>
           <ejb-ref-name>ejb/Book</ejb-ref-name>
           <ejb-ref-type>Entity</ejb-ref-type>
           <local-home>BookHome</local-home>
           <local>Book</local>
           <ejb-link>Book</ejb-link>
           </ejb-local-ref>


          should be declared as part of the session bean configuration:
          <session>
           <!-- All the session bean related configuration, goes here-->
          .....
           <!-- Local reference to the entity bean goes here -->
           <ejb-local-ref>
           <ejb-ref-name>ejb/Book</ejb-ref-name>
           <ejb-ref-type>Entity</ejb-ref-type>
           <local-home>BookHome</local-home>
           <local>Book</local>
           <ejb-link>Book</ejb-link>
           </ejb-local-ref>
          </session>


          • 2. Re: local entity bean lookup from session bean goes wrong
            Youri adcsdc Newbie

             

            "jaikiran" wrote:
            If you are trying to create a local ref for a entity bean inside a session bean, then this piece of code
             <ejb-local-ref>
             <ejb-ref-name>ejb/Book</ejb-ref-name>
             <ejb-ref-type>Entity</ejb-ref-type>
             <local-home>BookHome</local-home>
             <local>Book</local>
             <ejb-link>Book</ejb-link>
             </ejb-local-ref>


            should be declared as part of the session bean configuration:
            <session>
             <!-- All the session bean related configuration, goes here-->
            .....
             <!-- Local reference to the entity bean goes here -->
             <ejb-local-ref>
             <ejb-ref-name>ejb/Book</ejb-ref-name>
             <ejb-ref-type>Entity</ejb-ref-type>
             <local-home>BookHome</local-home>
             <local>Book</local>
             <ejb-link>Book</ejb-link>
             </ejb-local-ref>
            </session>


            You made my day! thank you