6 Replies Latest reply on May 18, 2005 9:53 AM by luis valenzuela

    autokey generation (3.2.5 + hypersonic)

    Gioele Barabucci Newbie

      I can't get hypersonic to generate primary keys for me in an automated way.

      This is what I have in jbosscmp-jdbc.xml

      <entity>
       <ejb-name>StudentGroup</ejb-name>
      
       <cmp-field>
       <field-name>id</field-name>
       <auto-increment/>
       </cmp-field>
      
       <cmp-field>
       <field-name>password</field-name>
       </cmp-field>
      
       <entity-command name="get-generated-keys">
      </entity-command>


      in ejb-jar.xml (some fields skipped)

      <entity>
       <ejb-name>StudentGroup</ejb-name>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Integer</prim-key-class>
       <reentrant>False</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>StudentGroup</abstract-schema-name>
      
       <cmp-field >
       <field-name>id</field-name>
       </cmp-field>
      
       <cmp-field >
       <field-name>password</field-name>
       </cmp-field>
      
       <primkey-field>id</primkey-field>
      </entity>


      Everytime I create a new StudentGroup I get a null value for getId (both in ejbCreate() and in ejbPostCreate). Obviously the DB ends up corrupted.

      What is the correct way to get the autogenerated key?

      I thought that with autogenerated primary keys all I had to do was to create a simple ejbCreate that ends with return getId();, being the id field already set by the DB. It seems that I am wrong.