3 Replies Latest reply on Jul 6, 2005 10:05 AM by schrouf

    Column XXXX cannot be null. why not Default value?

    svewap

      Hi, i have a problem with my mysql database-table. Im using jboss 4.0.2 final and MySQL 4.1.12a-nt.
      If jboss creates a record, jboss says:

      java.rmi.ServerException: EJBException:; nested exception is:
       javax.ejb.EJBException: Could not create entity:java.sql.SQLException: Column 'activated' cannot be null
      

      If i want to create an EJB i must set several values, with are NOT NULL. For example my Primary Key is created by the auto-increment function of my table. That works.
      But i have other columns which are NOT NULL but have a default value. So the sense of a default value is, that they are used, if no value is set.
      How can i tell jboss, that it doesn't set any value (only on creating)? Or there are other solutions?

      An example-field is:
      <cmp-field>
       <field-name>activated</field-name>
       <column-name>activated</column-name>
       <not-null />
       <jdbc-type>CHAR</jdbc-type>
       <sql-type>CHAR</sql-type>
       </cmp-field>


      Thanks for help.

        • 1. Re: Column XXXX cannot be null. why not Default value?
          svewap

          i have generally problems to insert datas into my mysql-table at ejbCreate or ejbPostCreate. For example:

           public Integer ejbCreate(Integer idcompanyuser, Integer companyid,
           String username) throws CreateException {
           setIdcompany(companyid); // -> works
           return null;
           }
          
           public void ejbPostCreate(Integer idcompanyuser, Integer companyid,
           String username) throws CreateException {
           setActivated("1"); // -> DOESN'T WORKS
           setCompanyusername(username); // -> works
           setConfirmed("0"); // -> works
           }


          The columns 'activated' and 'confirmed' have the type CHAR(1).
          I use the newest J-Connector of MySQL.

          (Nochwas: Für die vielen Views bin ich NICHT verantwortlich.)

          • 2. Re: Column XXXX cannot be null. why not Default value?
            svewap

            Ok, my last post was stupid and a case for the beginner's corner. a jbuilder 2005 problem.

            • 3. Re: Column XXXX cannot be null. why not Default value?
              schrouf

              NOT JBoss is complaining about a NULL value, it's your underlying database. Have you specified a default for your column within your table SQL DDL statement ?

              Regards
              Ulf