1 Reply Latest reply on Jun 6, 2003 2:06 AM by cbartling

    javax.ejb.CreateException: Could not create entity:java.sql.

    wangjun188 Newbie

      I developed a entity ejb,it deployed right,but when I access it,I get a CreateException,How can I solve it?
      Anyone can Help me?
      my jsp like that:
      <%@ page import="javax.ejb.*,javax.naming.InitialContext,java.util.Collection,java.util.Iterator,com.custom.*" %>

      my first database ejb program


      <%
      try
      {
      InitialContext ctx=new InitialContext();
      Object objRef=ctx.lookup("custom/Cmp1Custom");
      Cmp1CustomHome home=(Cmp1CustomHome)javax.rmi.PortableRemoteObject.narrow(objRef,Cmp1CustomHome.class);

      Cmp1Custom bean;

      bean=home.create("BK009","majun","shanghai");

      %>

      CustomID:<%=bean.getPrimaryKey()%>
      CompanyName:<%=bean.getCompanyName()%>
      ContactName:<td<%=bean.getContactName()%>



      <%
      }
      catch(javax.naming.NamingException ne)
      {
      %>
      Naming exception Caught:<%=ne%>
      <%
      }
      catch(javax.ejb.CreateException ce)
      {
      %>
      Create Exception Caught:<%=ce%>
      <%
      }
      catch(java.rmi.RemoteException re)
      {
      %>
      Remote Exception caught:"+<%=re%>;
      <%
      }


      %>


      my ejb-jar.xml like:
      ?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>
      entityBean
      <display-name>Customer</display-name>
      <enterprise-beans>

      <display-name>Cmp1Custom</display-name>
      <ejb-name>Cmp1Custom</ejb-name>
      com.custom.Cmp1CustomHome
      com.custom.Cmp1Custom
      <ejb-class>com.custom.Cmp1CustomEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Cmp1Custom</abstract-schema-name>


      <table-name>Customers</table-name>
      <create-table>false</create-table>
      <cmp-field>
      <field-name>CustomerID</field-name>
      <column-name>CustomerID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>CompanyName</field-name>
      <column-name>CompanyName</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>ContactName</field-name>
      <column-name>ContactName</column-name>
      </cmp-field>
      <primkey-field>CustomerID</primkey-field>

      </enterprise-beans>

      <assembly-descriptor>
      <container-transaction>

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

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

      my Cmp1CustomEJB.java like:
      package com.custom;
      import java.util.*;
      import javax.ejb.*;

      public abstract class Cmp1CustomEJB implements EntityBean
      {
      public String CustomerID;
      public String CompanyName;
      public String ContactName;
      public abstract void setCustomerID();
      public abstract String getCustomerID();
      public abstract void setCompanyName();
      public abstract void setContactName();
      public abstract String getCompanyName();
      public abstract String getContactName();

      public String ejbCreate(String CustomerID,String CompanyName,String ContactName) throws CreateException
      {

      if(CustomerID==null)
      throw new CreateException("The customerid is required");


      this.CustomerID="bk001";
      this.CompanyName="xjairlines";
      this.ContactName="urumqi";
      System.out.println("ejb create call!");
      return null;

      }

      public void ejbPostCreate(String CustomerID,String CompanyName,String ContactName){}
      public void ejbLoad(){}
      public void ejbStore(){}
      public void ejbRemove(){}
      public void unsetEntityContext(){}
      public void setEntityContext(EntityContext context){}
      public void ejbActivate(){}
      public void ejbPassivate(){}
      }




      I get the Exception:
      javax.ejb.CreateException: Could not create entity:java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO CMP1CUSTOM (CustomerID, CompanyName, ContactName) VALUES (NULL, NULL, NULL)]
      please help me,Thank you very meuch!
      wangjun188