2 Replies Latest reply on Apr 8, 2004 7:53 AM by Michael Forster

    Auto-Increment and findByPrimaryKey

    Michael Forster Newbie

      I am trying to implement Auto increment keys, in MySQL

      I have successfully got it to create the field (id) and it works successfully on adding a new record, - BUT

      on trying to findByPrimaryKey(Object id);

      it fails with an SQLException stating Cannot Find Column TransType_upk

      TransType is the name of the table - what do I need to put in and where to make it also recognise the pk as id

        • 1. Re: Auto-Increment and findByPrimaryKey
          Jeff Beal Newbie

          You have to configure this in the jbosscmp-jdbc.xml file. In my file, I have the following code in the defaults section:

          <unknown-pk>
           <unknown-pk-class>java.lang.Long</unknown-pk-class>
           <field-name>id</field-name>
           <column-name>ID</column-name>
           <jdbc-type>BIGINT</jdbc-type>
           <sql-type>BIGINT</sql-type>
           <auto-increment/>
           </unknown-pk>
           <entity-command name="mysql-get-generated-keys"/>

          The unknown-pk section sets up the default values that JBoss will use when it encounters an unknown primary key. The entity-command section tells JBoss how to get the information on the key generated by the database.

          Of course, for most entities sticking to a column named 'ID' isn't very cool, so in each entity where I use an unknown primary key, I can add an entity-specific unknown-pk element to configure the column name for that entity:
          <unknown-pk>
           <unknown-pk-class>java.lang.Long</unknown-pk-class>
           <field-name>userId</field-name>
           <column-name>USER_ID</column-name>
           </unknown-pk>
          


          Jeff Beal

          • 2. Re: Auto-Increment and findByPrimaryKey
            Michael Forster Newbie

            Great - Amazing

            We were missing the <field-name> and <column-name> that was all :-)

            Thanks again Great response.