6 Replies Latest reply on Jul 26, 2004 10:44 AM by Bryan Rank

    newbie PK problem

    Nathan Coast Newbie

      Hi,

      bound to be a simple solution....

      I'm using the default hypersonic db. I'm unable to get jboss to insert values for the pk for my entity beans. I get the error:

      Could not create entity:java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO ARTISTENTITY (artistName, recordLabel) VALUES ('default name', 'default label')]

      the only other column is id (the primary key)

      jbosscmp-jdbc.xml snip


      <ejb-name>ArtistEntity</ejb-name>
      <cmp-field>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>artistName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>recordLabel</field-name>
      </cmp-field>
      <entity-command name="hsqldb-fetch-key">
      </entity-command>


      JBoss seems to be ignoring the id column in the insert statement.

      any ideas what I've missed?

      thanks
      Nathan

        • 1. Re: newbie PK problem
          caetanovendrami Newbie

          I think you need an <unknown-pk> configuration.

          I'm using postgres with something like that:
          <unknown-pk>
          <unknown-pk-class>java.lang.Long</unknown-pk-class>
          <jdbc-type>INTEGER</jdbc-type>
          <sql-type>SERIAL</sql-type>
          <auto-increment/>
          </unknown-pk>

          I don't know the specific configuration for hsqldb

          • 2. Re: newbie PK problem
            Alexey Loubyansky Master

            No need for unknown-pk. Just mark the pk field as <auto-increment/>

            • 3. Re: newbie PK problem
              Nathan Coast Newbie

              thanks but still no cigar.


              <ejb-name>ArtistEntity</ejb-name>
              <cmp-field>
              <field-name>id</field-name>
              <auto-increment/>
              </cmp-field>
              <cmp-field>
              <field-name>artistName</field-name>
              </cmp-field>
              <cmp-field>
              <field-name>recordLabel</field-name>
              </cmp-field>
              <entity-command name="hsqldb-fetch-key">
              </entity-command>


              still getting exactly the same error as before:
              Could not create entity:java.sql.SQLException: Try to insert null into a non-nullable column in statement [INSERT INTO ARTISTENTITY (artistName, recordLabel) VALUES ('default name', 'default label')]

              also tried the unknown-pk which didn't work.

              Is it the responsibility of jboss or hypersonic to manage incrementing the pk as the insert statement seems to indicate that jboss is not looking after the pk.

              thanks
              Nathan

              • 4. Re: newbie PK problem
                Nathan Coast Newbie

                OK, phaps ignore previous post, I don't think the db tables were being recreated. After a restart, deployment gives me this error. I've checked the hypersonic docs and BIGINT is the correct translation for a java.lang.Long PK.

                java.sql.SQLException: Wrong data type: ID in statement [CREATE TABLE ARTISTENTITY (id BIGINT NOT NULL IDENTITY, artistName VARCHAR(256), recordLabel VARCHAR(256), CONSTRAINT PK_ARTISTENTITY PRIMARY KEY (id))])

                any ideas?

                cheers
                Nathan

                • 5. Re: newbie PK problem
                  Alexey Loubyansky Master

                  Looks like IDENTITY can't be defined on BIGINT. Also you should <pk-constraint>false</pk-constraint> for the entity because Hypersonic does not support IDENTITY and PRIMARY KEY constraint at the same time. So the statement should look like
                  CREATE TABLE ARTISTENTITY (id int NOT NULL IDENTITY, artistName VARCHAR(256), recordLabel VARCHAR(256))

                  • 6. Re: newbie PK problem
                    Bryan Rank Newbie

                    I'm having the same problem. Nathan, can you post your jbosscmp-jdbc.xml file? I'm all over the board on this and seeing yours would help.

                    Thanks