4 Replies Latest reply on Feb 15, 2002 5:55 AM by Paul Boddie

    auto_increment

    Boris Newbie

      Is there any way to use auto_increment integer type for primary key generation? Can I specify for instance in jbosscmp-jdbc.xml file the following for mySql mapping:
      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER auto_increment</sql-type>
      </cmp-field>
      I know auto_increment modifyer is lawful for mysql create table statement.

        • 1. Re: auto_increment
          Paul Boddie Newbie

          You might want to try...

          <sql-type>INTEGER auto_increment PRIMARY KEY</sql-type>

          This seems to work, although I have some other issues with entity beans at the moment.

          • 2. Re: auto_increment
            Paul Boddie Newbie

            Actually, this probably won't work at all. The primary key needs to be set during ejbCreate, but you don't have access to the generated value. Moreover, the entity bean doesn't seem to be able to "pick up" the generated value by itself. Therefore, you can't even provide a fake value and hope that it gets changed later.

            What we really need is "unknown primary keys", I think.

            • 3. Re: auto_increment
              David Jencks Master

              There is no way at all to do this now. Dain is working on a generic key generator for the cmp2. I am considering how to make it possible to use stored procedures for db access in cmp, which would provide an indirect solution (I think). (write a sp to do the insert, returning the id). My part is in the fairly distant future.

              • 4. Re: auto_increment
                Paul Boddie Newbie

                So far, all of the material I've found on unknown primary keys just restates the specification (isn't that always the case with EJB?), but the specification also seems to suggest that adding extra abstract methods, cmp-fields and possibly a constructor (where the primary key is set) is the way to go.

                That is, you add a constructor to the entity bean implementation and use some kind of generator there to set the primary key field. Should this work? (I can't seem to make it work yet.)