1 Reply Latest reply on Sep 4, 2002 5:45 AM by Scutaru Ionut

    context.lookup gives me javax.naming.NameNotFoundException

    Scutaru Ionut Newbie

      Hi, guys !
      I have a simple EJB that is already deployed with success. Here are my settings files:


      ***********
      ejb.xml
      ***********

      <?xml version="1.0"?>
      <!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>
      <enterprise-beans>

      <ejb-name>Author</ejb-name>
      <local-home>com.scutaru.biblioteca.LocalAuthorHome</local-home>
      com.scutaru.biblioteca.LocalAuthor
      <ejb-class>com.scutaru.biblioteca.AuthorBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Author</abstract-schema-name>
      <cmp-field>
      <field-name>authorID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>authorFirstName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>authorLastName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>authorBirthDate</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>books</field-name>
      </cmp-field>
      <primkey-field>authorID</primkey-field>

      <query-method>
      <method-name>findByLastName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[
      SELECT OBJECT(a)
      FROM Author a
      WHERE a.authorFirstName = ?1
      ]]>
      </ejb-ql>



      <ejb-name>Book</ejb-name>
      <local-home>com.scutaru.biblioteca.LocalBookHome</local-home>
      com.scutaru.biblioteca.LocalBook
      <ejb-class>com.scutaru.biblioteca.BookBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>BookBean</abstract-schema-name>
      <cmp-field>
      <field-name>bookID</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>title</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>printingDate</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>authors</field-name>
      </cmp-field>
      <primkey-field>bookID</primkey-field>

      <query-method>
      <method-name>findByTitle</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[
      SELECT OBJECT(a)
      FROM BookBean AS a
      WHERE a.title = ?1
      ]]>
      </ejb-ql>


      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>

      <ejb-name>Author</ejb-name>
      <method-name>*</method-name>


      <ejb-name>Book</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>

      <ejb-relation>
      <ejb-relation-name>Author-Book</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Authors write books
      </ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Author</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>books</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>
      Books have authors
      </ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>Book</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>authors</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>

      </ejb-jar>



      ***************
      jboss.xml
      ***************

      <?xml version="1.0" encoding="Cp1252"?>

      false
      <container-configurations />
      <resource-managers />
      <enterprise-beans>

      <ejb-name>Author</ejb-name>
      <jndi-name>biblioteca/Author</jndi-name>


      <ejb-name>Book</ejb-name>
      <jndi-name>biblioteca/Book</jndi-name>

      </enterprise-beans>



      *****************
      jndi.properties
      *****************

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost:1099

      I checked at the following page: http://localhost:8082 and my bean looks like this:

      ........
      jboss.j2ee
      ...
      service=EJB,jndiName=biblioteca/Author
      service=EJB,jndiName=biblioteca/Book
      ...

      Then why, when I try to lookup "biblioteca/Author" it gives me :

      javax.naming.NameNotFoundException: biblioteca not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
      at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)

      Here is my client source code:

      public static void main(String[] args) throws Exception {
      Properties props = System.getProperties();
      Context ctx = new InitialContext(props);
      System.out.println(">> 1");
      Object obj = ctx.lookup("biblioteca/Author");
      System.out.println(">> 2");

      LocalAuthorHome home = (LocalAuthorHome)javax.rmi.PortableRemoteObject.narrow(obj, LocalAuthorHome.class);
      LocalAuthor author = home.create("test1","test2",new java.sql.Date(System.currentTimeMillis()));
      System.out.println(author.getAuthorLastName());
      // author.remove();
      }

      Thank you very much,
      Ionut