3 Replies Latest reply on Mar 3, 2009 7:49 AM by Wolfgang Knauf

    (debian,eclipse) javax.naming.NameNotFoundException: Custome

    olivier SAINT-EVE Newbie

      hello,

      I can"t access to a EJB via JNDI.
      here is the stuff I use : eclipse ganymède JEE, JBOSS 4.2.2 (modified to be used with MySQL).
      I have created an EAR project (enterprise application project), names petstore_ear, which contains several projects: an EJB project which contains many EJBs, a JPA project which contains manu entities, and a java project which contains a java class with a main class (it is the client class).

      when I launch firefox with the address "localhost:8080" and I select the jndi view, I see that the project is well deployed :

      Global JNDI Namespace

      +- petstore_ear (class: org.jnp.interfaces.NamingContext)
      | +- CustomerBean (class: org.jnp.interfaces.NamingContext)
      | | +- local (proxy: $Proxy109 implements interface ejb.customer.CustomerLocal,interface org.jboss.ejb3.JBossProxy)
      | | +- remote (proxy: $Proxy108 implements interface ejb.customer.CustomerRemote,interface org.jboss.ejb3.JBossProxy)
      | +- OrderSB (class: org.jnp.interfaces.NamingContext)
      | | +- local (proxy: $Proxy113 implements interface ejb.order.OrderLocal,interface org.jboss.ejb3.JBossProxy)
      | | +- remote (proxy: $Proxy112 implements interface ejb.order.OrderRemote,interface org.jboss.ejb3.JBossProxy)
      | +- CatalogSB (class: org.jnp.interfaces.NamingContext)
      | | +- local (proxy: $Proxy105 implements interface ejb.catalog.CatalogLocal,interface org.jboss.ejb3.JBossProxy)
      | | +- remote (proxy: $Proxy104 implements interface ejb.catalog.CatalogRemote,interface org.jboss.ejb3.JBossProxy)


      but when I try to access to in within the following java class I have the error:"javax.naming.NameNotFoundException: CustomerBean not bound".

      client:
      public static void main(String[] args) {
      
       try {
       Context ctx=new InitialContext();
      
       ejb.customer.CustomerRemote rem=(ejb.customer.CustomerRemote) ctx.lookup("CustomerBean/remote");
       rem.createCustomer(new Customer(1L,"jambon","rose","jean","bonrause","0018654118","jeanroi@gmail.com",new java.util.Date(1978,02,10),19,null),new source.Address(1,"4 rue des roses","","METZ","Moselle","57000","FRANCE"));
      
      
       System.out.println ("--- Hello, clients ---");
       for (source.customer.Customer client : rem.findCustomers()) {
       System.out.println ("client : "+client);
       }
      
       } catch (Exception e) {
       e.printStackTrace();
       }
       }


      I use a jndi.properties file to configure JNDI :
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=jnp://localhost:1099
      jnp.disableDiscovery=true


      here is the ejb-jar.xml file in the EJB project:
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
       <display-name>
      petstore_ejb </display-name>
       <ejb-client-jar>petstore_ejbClient.jar</ejb-client-jar>
      </ejb-jar>


      and I added a persistence.xml file always in the META-INF directory of my EJB project:
      <persistence>
       <persistence-unit name="petstorePU">
       <jta-data-source>java:/MySqlDS</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="update"/>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.connection.password" value="petstorepwd"/>
       <property name="hibernate.connection.username" value="petstorelg"/>
       </properties>
       </persistence-unit>
      </persistence>
      


      if you want some other stuff, tell me it.

      olivier.

        • 1. Re: (debian,eclipse) javax.naming.NameNotFoundException: Cus
          Sandor Fiedler Newbie

          As per your listing of the JNDView try this JNDI-Name

          petstore_ear/CustomerBean/remote

          • 2. Re: (debian,eclipse) javax.naming.NameNotFoundException: Cus
            olivier SAINT-EVE Newbie

            hello,

            thanks for your reply.
            I changed the code of the client, and now I have the following error : "javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: source.customer.Customer".

            the class it speaks about is a class I created in a JPA project.
            I added references to this JPA project in the EJB project, in the properties / "java build path" / projects, in "properties" / "java build path" / "order and export" (item enabled),"properties" / "java EE module dependencies" / (JPA .jar enabled), and in "properties" / "project references" (item "petstore_jpa" enabled).

            more references seems to be impossible, and yet I have an error telling me the JPA project isn't found.

            olivier.

            • 3. Re: (debian,eclipse) javax.naming.NameNotFoundException: Cus
              Wolfgang Knauf Master

              Hi Olivier,

              "Customer" is an entity bean?

              Locate the "source.customer.Customer" class in the EAR file which is deployed to the server. It should contain either the class file, or a JAR containing the entity class should be located in "META-INF/lib" of your application client JAR (and the "Classpath" entry in "Manifest.mf" should reference it).

              But as you use eclipse: why don't you add the Entities to your EJB project? This is the easiest way to handle entity beans. Your application client project could reference the "EJB client JAR" instead of the full EJB jar.

              Wolfgang