2 Replies Latest reply on Mar 22, 2004 8:54 AM by neva

    EJB Creation Error Column does not allow nulls

    Jerrold Eads Newbie

      I am trying to run a unit test on an entity bean I have built and I get a creation error stating that a non nullable field has been initiated with a null. In the log I see that the specified field is not null so where is the null comming from. Attached is enough to hopefully figure this one out.

      jbosscmp-jdbc.xml
      < ejb-relation>
      < ejb-relation-name>ActivityEventCode_activityGroup</ejb-relation-name>
      < !-- Says that we're doing a foreign key map instead of an intersection table map (relation-table-mapping)-->
      < foreign-key-mapping/>
      < ejb-relationship-role>
      < ejb-relationship-role-name>ActivityEventCode_has_ActivityGroupCode< /ejb-relationship-role-name>
      < !-- No key fields, since ActivityGroupCode has no foreign key -->
      < key-fields/>
      < /ejb-relationship-role>
      < ejb-relationship-role>
      < ejb-relationship-role-name>ActivityGroupCodeRole< /ejb-relationship-role-name>
      < key-fields>
      < key-field>
      < !-- CMP field from the ActivityGroupCode object -->
      < field-name>activityGroupCode< /field-name>
      < !-- Foreign Key in the ActivityEventCode table that maps to this ID -->
      < column-name>ActivityGroup< /column-name>
      < /key-field>
      < /key-fields>
      < /ejb-relationship-role>
      < /ejb-relation>

      ejb-jar.xml
      < relationships>
      < !-- this is a One to Many Unidirectional relationship -->
      < ejb-relation>
      < ejb-relation-name>ActivityEventCode_activityGroup< /ejb-relation-name>
      < ejb-relationship-role>
      < description>ActivityEventCode has one ActivityGroupCode< /description>
      < ejb-relationship-role-name>ActivityEventCode_has_ActivityGroupCode< /ejb-relationship-role-name>
      < multiplicity>Many< /multiplicity>
      < cascade-delete/>
      < relationship-role-source>
      < ejb-name>MSSQLServer2000MetaData_ActivityEventCode< /ejb-name>
      < /relationship-role-source>
      < cmr-field>
      < cmr-field-name>activityGroup< /cmr-field-name>
      < /cmr-field>
      < /ejb-relationship-role>
      < ejb-relationship-role>
      < description>one ActivityGroupCode exists for ActivityEventCode< /description>
      < ejb-relationship-role-name>ActivityGroupCodeRole< /ejb-relationship-role-name>
      < multiplicity>One< /multiplicity>
      < relationship-role-source>
      < description>ActivityGroupCode< /description>
      < ejb-name>MSSQLServer2000MetaData_ActivityGroupCode< /ejb-name>
      < /relationship-role-source>
      < /ejb-relationship-role>
      < /ejb-relation>

      ActivityEvenCodeHome.java
      public interface ActivityEventCodeHome extends javax.ejb.EJBLocalHome
      {
      public ActivityEventCode create(
      java.lang.String eventCode,
      java.lang.String description,
      java.util.Date dateCreated,
      java.lang.String createdBy,
      java.util.Date dateModified,
      java.lang.String modifiedBy,
      ActivityGroupCode activityGroup ) throws CreateException;

      public ActivityEventCode findByPrimaryKey(ActivityEventCodePK pk) throws FinderException;
      public Collection findAll() throws FinderException;
      }
      AcitivityEventCodeBean.java
      public ActivityEventCodePK ejbCreate(
      java.lang.String eventCode,
      java.lang.String description,
      java.util.Date dateCreated,
      java.lang.String createdBy,
      java.util.Date dateModified,
      java.lang.String modifiedBy,
      ActivityGroupCode activityGroup ) throws CreateException
      {
      log.debug("ejbCreate");

      // Set the logged in user name
      String currentUser = EjbUtilities.getCurrentUserName(this.entityContext);

      // Set the creation date to the current date/time
      java.util.Date dt = DateTimeUtilities.getCurrentGmtDateTime();

      // Set the Primary Key Field/s
      this.setEventCode(eventCode);

      this.setDescription(description);
      if (dateCreated == null)
      {
      this.setDateCreated(dt);
      }
      else
      {
      this.setDateCreated(dateCreated);
      }
      if (createdBy == null)
      {
      this.setCreatedBy(currentUser);
      }
      else
      {
      this.setCreatedBy(createdBy);
      }
      if (dateModified == null)
      {
      this.setDateModified(dt);
      }
      else
      {
      this.setDateModified(dateModified);
      }
      if (modifiedBy == null)
      {
      this.setModifiedBy(currentUser);
      }
      else
      {
      this.setModifiedBy(modifiedBy);
      }
      return null;
      }

      /**
      * Post Create set up CMR for the bean.
      *
      * @param eventCode
      * @param description (can be null)
      * @param dateCreated
      * @param createdBy
      * @param dateModified
      * @param modifiedBy
      * @param activityGroup
      * @throws CreateException
      */
      public void ejbPostCreate(
      java.lang.String eventCode,
      java.lang.String description,
      java.util.Date dateCreated,
      java.lang.String createdBy,
      java.util.Date dateModified,
      java.lang.String modifiedBy,
      ActivityGroupCode activityGroup ) throws CreateException
      {
      log.debug("ejbPostCreate");

      this.setActivityGroup(activityGroup);
      }

      Creation error:
      2004-03-05 13:13:50,796 INFO [com.synapps.jmx.jaas.srp.DatabaseVerifierStore] New User Added: unittest
      2004-03-05 13:13:54,031 DEBUG [com.genecodes.mssqlserver2000metadata.entitybeantest.EntityBeanTestBean] setSessionContext
      2004-03-05 13:13:54,031 DEBUG [com.genecodes.mssqlserver2000metadata.entitybeantest.EntityBeanTestBean] ejbCreate
      2004-03-05 13:13:54,140 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] ****EJB Called: MSSQLServer2000MetaData_ActivityGroupCode
      2004-03-05 13:13:54,140 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] Start method: create
      2004-03-05 13:13:54,140 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] InvokeHome: create(GCASTGCASTGC,C,Tue Mar 16 16:59:36 CST 2004,STGCASTGCASTGC,Tue Mar 16 16:59:36 CST 2004,STGCASTGCASTGC)
      2004-03-05 13:13:54,140 DEBUG [com.genecodes.mssqlserver2000metadata.activitygroupcode.ActivityGroupCodeBean] setEntityContext
      2004-03-05 13:13:54,171 DEBUG [com.genecodes.mssqlserver2000metadata.activitygroupcode.ActivityGroupCodeBean] ejbCreate
      2004-03-05 13:13:54,218 DEBUG [com.genecodes.mssqlserver2000metadata.activitygroupcode.ActivityGroupCodeBean] ejbPostCreate
      2004-03-05 13:13:54,218 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] End method=create
      2004-03-05 13:13:54,281 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] ****EJB Called: MSSQLServer2000MetaData_ActivityEventCode
      2004-03-05 13:13:54,281 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] Start method: create
      2004-03-05 13:13:54,281 DEBUG [com.genecodes.jboss.interceptors.MetaDataInterceptor] InvokeHome: create(STGCASTGC,C,Fri Mar 12 19:22:16 CST 2004,GCASTGCASTGC,Fri Mar 12 14:14:28 CST 2004,ASTGCASTGC,MSSQLServer2000MetaData_ActivityGroupCode:Primary key: GCASTGCASTGC)
      2004-03-05 13:13:54,281 DEBUG [com.genecodes.mssqlserver2000metadata.activityeventcode.ActivityEventCodeBean] setEntityContext
      2004-03-05 13:13:54,281 DEBUG [com.genecodes.mssqlserver2000metadata.activityeventcode.ActivityEventCodeBean] ejbCreate
      2004-03-05 13:13:54,281 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.MSSQLServer2000MetaData_ActivityEventCode] Could not create entity
      java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'ActivityGroup', table 'MetaData.dbo.ActivityEventCode'; column does not allow nulls. INSERT fails.

      Please help.

      Jerry