2 Replies Latest reply on May 14, 2005 9:13 AM by gioele

    autogenerated pk with hypersonic

    gioele

      I'd like to have an autogenerated pk but jboss 3.2.5 refuses to create this EJB.

      This is the EJB I created (I kept only the interesting xdoclet tags):

      /**
       * @ejb.bean name="StudentGroup"
       * local-jndi-name="ejb/StudentGroup"
       * type="CMP"
       * cmp-version="2.x"
       * primkey-field="id"
       * @jboss.persistence pk-constraint="false"
       * @jboss.entity-command name="hsqldb-fetch-key"
       */
      public abstract class StudentGroupBean implements EntityBean {
      
       /**
       * @ejb.create-method view-type = "local"
       */
       public Integer ejbCreate(String password)
       throws javax.ejb.CreateException {
       setPassword(password);
       return null;
       }
      
       /**
       * @ejb.persistent-field
       * @jboss.persistence auto-increment="true"
       */
       public abstract Integer getId();
      
       ...


      The table is created, by jboss, with this command
      CREATE TABLE STUDENTGROUP (id INTEGER NOT NULL, password VARCHAR(256), article VARCHAR(256),
      CONSTRAINT PK_STUDENTGROUP PRIMARY KEY (id))


      CONSTRAINT... why? I used pk-constraint="false"


      When I try to add a new StudentGroup, I get
      19:00:03,909 ERROR [StudentGroup] Could not create entity
      java.sql.SQLException: Try to insert null into a non-nullable column in statement
      [INSERT INTO STUDENTGROUP (id, password, article) VALUES (NULL, 'pw', NULL)]


      why the first NULL? shouldn't jboss place the value returned by the DB in the pk?

        • 1. Re: autogenerated pk with hypersonic
          gioele

          I created the table myself (a quick hack, I need jboss to do it) with

          CREATE TABLE STUDENTGROUP (
           id INTEGER NOT NULL IDENTITY,
           password VARCHAR(256),
           article VARCHAR(256)
          )


          now, during the creation of a new StudentGroup, JBoss complains with
          javax.ejb.CreateException: Primary key for created instance is null.


          any suggested solution?
          How can I make JBoss create the table in a correct way (with IDENTITY)?

          • 2. Re: autogenerated pk with hypersonic
            gioele

            The problem was that jbosscmp-jdbc.xml was not included in the correct jar file. Now the problem seems solved.