2 Replies Latest reply on Apr 23, 2004 8:04 AM by Michael Forster

    Won't use manually generated CMP primary keys.

    Matthew Greet Newbie

      I can create Long primary keys on mySQL using auto-increment fields. For one table, I need to generate the Long number myself. If I disable auto-increment, I get

      getGeneratedKeys returned an empty ResultSet

      If I enable auto-increment for the primary key, JBoss ignores the id I set in ejbCreate and uses its own.

      JBoss is clearly generating the next id for use but I don't want it to. How do I tell JBoss to stop, without resorting to BMP?

        • 1. Re: Won't use manually generated CMP primary keys.
          Michael Forster Newbie

          The problem we are having is a strange one, on Every table Exept this one and one other we require an auto-increment PK,

          With this one we are passing in the value we require for the primary key, but we are getting the error

          at java.lang.Thread.run(Thread.java:536)
          12:21:18,933 ERROR [LogInterceptor] TransactionRolledbackException in method: pu
          blic abstract java.lang.Long com.ingotz.points.core.usecase.Test.testCard() thro
          ws java.rmi.RemoteException, causedBy:
          javax.ejb.EJBException: getGeneratedKeys returned an empty ResultSet
          at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand.executeI
          nsert(JDBCMySQLCreateCommand.java:77)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInser
          t(JDBCAbstractCreateCommand.java:287)
          at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBC
          AbstractCreateCommand.java:138)


          from what we can see we are doing nothing out of the ordinary....

          The ejbCreate() function is as follows

          public Long ejbCreate(Long id,int pin) throws CreateException
          {
          setId(id);
          setPin(pin);
          return null;
          }

          The ejb-jar is as follows

          <ejb-name>CardBean</ejb-name>
          com.ingotz.points.core.entity.CardHome
          com.ingotz.points.core.entity.Card
          <local-home>com.ingotz.points.core.entity.CardLocalHome</local-home>
          com.ingotz.points.core.entity.CardLocal
          <ejb-class>com.ingotz.points.core.entity.CardBean</ejb-class>
          <persistence-type>Container</persistence-type>
          <prim-key-class>java.lang.Long</prim-key-class>
          False
          <cmp-field><field-name>id</field-name></cmp-field>
          <cmp-field><field-name>pIN</field-name></cmp-field>
          <cmp-field><field-name>password</field-name></cmp-field>
          <cmp-field><field-name>state</field-name></cmp-field>
          <cmp-field><field-name>expiryDate</field-name></cmp-field>
          <cmp-field><field-name>changeAuth</field-name></cmp-field>
          <cmp-field><field-name>deadReason</field-name></cmp-field>
          <cmp-field><field-name>lastLoginDate</field-name></cmp-field>
          <cmp-field><field-name>loginFailures</field-name></cmp-field>
          <cmp-field><field-name>timestamp</field-name></cmp-field>
          <primkey-field>id</primkey-field>
          <cmp-version>2.x</cmp-version>
          <abstract-schema-name>CardBeanAPS</abstract-schema-name>
          <resource-ref>
          <res-ref-name>jdbc/mysql</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          </resource-ref>


          The jdbc-cmp xml is as follows


          <ejb-name>CardBean</ejb-name>
          <table-name>card</table-name>
          <cmp-field>
          <field-name>id</field-name>
          <column-name>cd_id</column-name>
          <not-null/>
          </cmp-field>
          <cmp-field>
          <field-name>pIN</field-name>
          <column-name>cd_pin</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>password</field-name>
          <column-name>cd_password</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>state</field-name>
          <column-name>cd_state</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>expiryDate</field-name>
          <column-name>cd_expire</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>changeAuth</field-name>
          <column-name>cd_changeauth</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>deadReason</field-name>
          <column-name>cd_dead_reason</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>lastLoginDate</field-name>
          <column-name>cd_last_log_att</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>loginFailures</field-name>
          <column-name>cd_failed_logins</column-name>
          </cmp-field>
          <cmp-field>
          <field-name>timestamp</field-name>
          <column-name>cd_timestamp</column-name>
          </cmp-field>



          What are we doing wrong?

          • 2. Re: Won't use manually generated CMP primary keys.
            Michael Forster Newbie

            We sorted the problem,

            We had our <entity-command> for the autoincrement primary keys in the default section of the jbosscmp-jdbc.xml file, on moving it to the entity sections of the tables needing autoincrement solved the problem.