6 Replies Latest reply on Sep 9, 2005 11:57 AM by Wessel de Roode

    Could not instantiate the bean, Urgent help please

    krishkumar Newbie

      When I try to instantiate a Entity (CMP) Bean I am getting following error. What am I missing. Please help.

      Got context
      LOADED Product BEAN

      java.rmi.ServerException: RemoteException occurred in server thread; nested exce
      ption is:
      java.rmi.ServerException: EJBException:; nested exception is:
      javax.ejb.EJBException: Could not instantiate bean; CausedByException is
      :
      com.DS.EntityBean.ProductBean

        • 1. Re: Could not instantiate the bean, Urgent help please
          Raja Master

          Post some code, I would check the setEntityContext and teh constructor(if you have one) for the EntityBean.

          • 2. Re: Could not instantiate the bean, Urgent help please
            krishkumar Newbie

            Thank you for thr immediate reply, here is the src for ProductPK.java and ProductBean.java,

            ProductPk.java :
            ____________

            public class ProductPK implements Serializable{

            public String productID;

            public ProductPK( String id) {
            this.productID = id;
            }

            public ProductPK() {

            }

            public String toString() {
            return productID.toString();
            }

            public int hashCode() {
            return productID.hashCode();
            }

            public boolean equals( Object prod) {
            return ((ProductPK)prod).productID.equals(productID);
            }

            }

            ProductBean.java
            _______________

            public abstract class ProductBean implements EntityBean {

            protected EntityContext ctx;

            public ProductBean() {

            }

            public abstract void setName(String name);
            public abstract void setDescription(String desc);
            public abstract void setBasePrice(double price);
            public abstract void setProductID(String id);

            public abstract String getName();
            public abstract String getDescription();
            public abstract double getBasePrice();
            public abstract String getProductID();

            public void ejbActivate() {
            System.out.println("ejbActivate Method called ");
            }

            public void ejbPassivate() {
            System.out.println("ejbPassivate Method called ");
            }

            public void ejbLoad() {
            System.out.println("ejbLoad Method called ");
            }

            public void ejbStore() {
            System.out.println("ejbStore Method called ");
            }

            public void ejbRemove() {
            System.out.println("ejbRemove Method Called ");
            }

            public void setEntityContext(EntityContext ctx) {
            this.ctx = ctx;
            }

            public void unsetEntityContext() {
            this.ctx = null;
            }

            public void ejbPostCreate(String id,String name,String desc,double price) {
            System.out.println( " ejbPostCreate called ");
            }

            public String ejbCreate(String productid,String name, String description,double price){
            System.out.println( "ejbCreate Called ");
            setProductID(productid) ;
            setName(name);
            setDescription(description);
            setBasePrice(price);

            return new ProductPK(productid).toString();
            }
            }

            • 3. Re: Could not instantiate the bean, Urgent help please
              Raja Master

              Your ejbCreate should return the Primary key class, so it should return ProductPK and not String. It should have definitely not deployed properly if the deployment descriptor reflects this.

              • 4. Re: Could not instantiate the bean, Urgent help please
                krishkumar Newbie

                Deployment procedure went without any problem. I made changes to Bean class to return ProductPK from ejbCreate function. I am still getting the same error, I have attached the client code for your reference. Thanks for your help.

                public class ProductClient {

                public static void main (String args[]) {

                // preparing properties for constructing an InitialContext object
                Properties properties = new Properties();
                properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                properties.put(Context.PROVIDER_URL, "localhost:1099");

                try {
                // Get an initial context
                InitialContext jndiContext = new InitialContext(properties);
                System.out.println("Got context");

                Object ref = jndiContext.lookup("Product");
                ProductHome productHome = (ProductHome)PortableRemoteObject.narrow (ref, ProductHome.class);
                System.out.println("LOADED Product BEAN");

                productHome.create("PC2300","P5-350","350 Mhz Pentium",200);
                productHome.create("PC2301","P5-400","400 Mhz Pentium",250);

                System.out.println("Products created ");
                }
                catch(Exception e) {
                System.out.println(e.toString());
                }
                }
                }

                • 5. Re: Could not instantiate the bean, Urgent help please
                  Jon Martin Solaas Newbie

                  Also post some more of the exception trace, in the original posting it seems it was cut off just when it was beginning to get interesting ....

                  • 6. Re: Could not instantiate the bean, Urgent help please
                    Wessel de Roode Newbie

                    Check if there are any errors during deploying.

                    I've been searching my head of for over 4 hours to find out why this error is occuring. Finaly i found out that one of my EJB-QL queries had an error on a total different bean, and it had it's effect on the bean that coun't instantiated.

                    My tip, check if there are already errors during deploying your beans. this might be the key to your dropout later.

                    Wessel de Roode