0 Replies Latest reply on Nov 17, 2004 2:59 PM by Dave

    auto-increment problem on PostgreSQL

    Dave Newbie

      I think I read every last post, every last set of instructions, every snippet of anything I could find in the forums as well as some external articles published on how to get auto-increment (auto generated primary keys to work) but none of them seemed to work with my configuration:

      JBOSS 4.0
      Postgres 7.3.x

      JbossCMP would not generate a new key so the insert to the database would fail with a not null constraint violation ...

      I tried all of the instructions about removing the cmp-field for my primary key and using prim-key-class of java.lang.Object and changing my bean class' ejbCreate to return an Object ... still, no luck ... but I stumbled onto this workaround by accident and hope that it will help some other people ... It basically comes down to using the 'pk-sql' EntityCommand instead of the 'postgresql-fetch-seq' EntityCommand ... Here is my example:




       <entity-command name="pk-sql">
       <attribute name="pk-sql">SELECT NEXTVAL('SEQ_PATRON') AS next_id</attribute>

      I did a cursory review of the JDBCPkSqlCreateCommand and JDBCPostgreSQLCreateCommand classes and it appears as though they implement different methods ... so I can't explain why my new value from the sequence is being inserted properly into the SQL that goes to the DB using the pk-sql entity command and why it isn't working for the postgresql-fetch-seq command ...

      So anyway, hopefully this workaround will save other people hours of searching too ...