1 Reply Latest reply on Mar 10, 2004 10:51 AM by M B

    JBoss/(Entity Bean Beginner Question

    M B Newbie

      hello

      I'm trying to deploy a simple entity bean that uses cmp and models a customer. Therefore I've written a CustomerBean, a CustomerRemote, CustomerHomeRemote. In addition I've also made CustomerLocal and CustomerHomeLocal interfaces (later the customer shall maintain a cmp-relationship with an address entity bean). All files compile without errors.

      I also wrote the ejb-jar.xml and jboss.xml files.

      After packaging and copying the customer.jar to JBoss' deploy directory, the Bean seams to be deployed correctly but after trying to test the bean with a client, I get an error message.

      JBoss output after deployment:

      15:02:50,311 INFO [MainDeployer] Starting deployment of package: file:/usr/local/jboss-3.2.3/server/default/deploy/customer.jar
      15:02:50,316 INFO [MainDeployer] Deployed package: file:/usr/local/jboss-3.2.3/server/default/deploy/customer.jar

      Error Message of CustomerClient_1:

      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:217)
      at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.init(InitialContext.java:219)
      at javax.naming.InitialContext.(InitialContext.java:195)
      at CustomerClient_1.getInitialContext(CustomerClient_1.java:57)
      at CustomerClient_1.main(CustomerClient_1.java:25)

      If I use the example files 04_1 of o'reillys ejb workbook, which I used as blueprints, the deployment works fine.

      I apologize for inserting all files and the error message, but it may be helpful for giving me a hint.

      cu,
      martin

      ps: sorry for any grammar and/or spelling errors.

      CustomerClient_1.java

      import com.ejbemarketplace.customer.*;
      
      import javax.naming.InitialContext;
      import javax.naming.Context;
      import javax.naming.NamingException;
      import java.rmi.RemoteException;
      import java.util.Properties;
      import javax.rmi.PortableRemoteObject;
      
      import java.util.GregorianCalendar;
      import java.util.Date;
      import java.text.DateFormat;
      
      public class CustomerClient_1 {
      
       /** Creates a new instance of CustomerClient_1 */
       public static void main(String[] args) {
       try {
       Context jndiContext = getInitialContext();
       Object ref = jndiContext.lookup("CustomerHomeRemote");
       CustomerHomeRemote home = (CustomerHomeRemote)PortableRemoteObject.narrow(ref, CustomerHomeRemote.class);
      
       DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
       GregorianCalendar bd = new GregorianCalendar();
       try {
       bd.setTime(df.parse("03/03/1946"));
       } catch (java.text.ParseException pe) { pe.printStackTrace(); }
      
       CustomerRemote customer = home.createCustomer("Bayer", "Martin", bd, "secret");
      
       Integer pk = new Integer(1);
      
       CustomerRemote customer_r = home.findByPrimaryKey(pk);
       System.out.println(customer_r.getLName());
       System.out.println(customer_r.getFName());
       System.out.println(customer_r.getDOBirth().toString());
       System.out.println(customer_r.getPasswd());
      
       } catch (java.rmi.RemoteException re) { re.printStackTrace(); }
       catch (javax.naming.NamingException ne) { ne.printStackTrace(); }
       catch (javax.ejb.CreateException ce) { ce.printStackTrace(); }
       catch (javax.ejb.FinderException fe) { fe.printStackTrace(); }
       }
      
       public static Context getInitialContext() throws javax.naming.NamingException {
       Properties p = new Properties();
       p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
       p.put(Context.PROVIDER_URL, "localhost:1099");
      
       return new javax.naming.InitialContext(p);
       }
      }
      


      CustomerHomeRemote.java
      package com.ejbemarketplace.customer;
      
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import java.util.GregorianCalendar;
      
      public interface CustomerHomeRemote extends javax.ejb.EJBHome {
      
       public CustomerRemote createCustomer(String lname, String fname, GregorianCalendar dobirth, String passwd)
       throws CreateException, RemoteException;
      
       public CustomerRemote findByPrimaryKey(Integer pk)
       throws FinderException, RemoteException;
      }
      


      CustomerRemote.java
      package com.ejbemarketplace.customer;
      
      import java.rmi.RemoteException;
      
      import java.util.Date;
      
      public interface CustomerRemote extends javax.ejb.EJBObject {
       public int getUCID() throws RemoteException;
      
      
       public String getLName() throws RemoteException;
       public void setLName(String lname) throws RemoteException;
      
       public String getFName() throws RemoteException;
       public void setFName(String fname) throws RemoteException;
      
       public Date getDOBirth() throws RemoteException;
       public void setDOBirth(Date dobirth) throws RemoteException;
      
       public String getPasswd() throws RemoteException;
       public void setPasswd(String passwd) throws RemoteException;
      }
      
      


      ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <!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>
       <entity>
       <ejb-name>CustomerEJB</ejb-name>
       <home>com.ejbemarketplace.customer.CustomerHomeRemote</home>
       <remote>com.ejbemarketplace.customer.CustomerRemote</remote>
       <!--
       <local-home>com.ejbemarketplace.customer.CustomerHomeLocal</local-home>
       <local>com.ejbemarketplace.customer.CustomerLocal</local>
       -->
       <ejb-class>com.ejbemarketplace.customer.CustomerBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Integer</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>Customer</abstract-schema-name>
       <cmp-field><field-name>ucid</field-name></cmp-field>
       <cmp-field><field-name>lname</field-name></cmp-field>
       <cmp-field><field-name>fname</field-name></cmp-field>
       <cmp-field><field-name>dobirth</field-name></cmp-field>
       <cmp-field><field-name>passwd</field-name></cmp-field>
       <primkey-field>ucid</primkey-field>
       <security-identity><use-caller-identity/></security-identity>
       </entity>
       </enterprise-beans>
       <assembly-descriptor>
       <security-role>
       <description>
       This role represents a user that has access to the e-bean's
       methods
       </description>
       <role-name>User</role-name>
       </security-role>
       <method-permission>
       <role-name>User</role-name>
       <method>
       <ejb-name>CustomerEJB</ejb-name>
       <method-name>*</method-name>
       </method>
       </method-permission>
       <container-transaction>
       <method>
       <ejb-name>CustomerEJB</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       </assembly-descriptor>
      </ejb-jar>
      


      jboss.xml
      <?xml version="1.0"?>
      
      <jboss>
       <enterprise-beans>
       <entity>
       <ejb-name>CustomerEJB</ejb-name>
       <jndi-name>CustomerHomeRemote</jndi-name>
       </entity>
       </enterprise-beans>
      </jboss>
      


        • 1. Re: JBoss/(Entity Bean Beginner Question
          M B Newbie

          Hi,

          sorry for bothering you with this question. I have found the error.
          I learn according to the book Enterprise JavaBeans 3rd Ed. I put the META-INF dir as said in the book and the picture on page 99 - which was an error.

          The book seems to have a few printing errors, but I discovered an errata at O'Reilly's homepage.

          Having it a couple of days earlier would have saved me a lot of time.

          cya,
          martin

          ps: sorry for spelling and/or grammar mistakes.
          pps: further questions are surely up-coming. sorry.