1 Reply Latest reply on Aug 10, 2005 3:54 AM by eric es

    PostgreSQL key generation

    Anton Gavazuk Newbie

      Hello all
      I use JbOss 4.0.2 & PostgreSQL 8

      I have create simple entity bean and I want use key generator (simple autoincrement)
      this is ejb-jar.xml


      <ejb-name>PersonEJB</ejb-name>
      amc.ejb.cmp.PersonHome
      amc.ejb.cmp.Person
      <local-home>amc.ejb.cmp.LocalPersonHome</local-home>
      amc.ejb.cmp.LocalPerson
      <ejb-class>amc.ejb.cmp.PersonBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>PersonEJB</abstract-schema-name>
      <cmp-field>
      <field-name>personid</field-name>
      </cmp-field>
      - KEY FIELD
      <cmp-field>
      <field-name>status</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>docid</field-name>
      </cmp-field>
      <primkey-field>personid</primkey-field>


      I have tried different ways for fix this problem in jboss-jdbc.xml

      first try


      <ejb-name>PersonEJB</ejb-name>
      <table-name>tbl_persons</table-name>
      <cmp-field>
      <field-name>docid</field-name>
      <column-name>DOCID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>status</field-name>
      <column-name>STATUS</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>personid</field-name>
      <column-name>PERSON_ID</column-name>
      <auto-increment/>
      </cmp-field>
      <entity-command name="postgresql-fetch-seq"/>



      second


      <ejb-name>PersonEJB</ejb-name>
      <table-name>tbl_persons</table-name>
      <cmp-field>
      <field-name>docid</field-name>
      <column-name>DOCID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>status</field-name>
      <column-name>STATUS</column-name>
      </cmp-field>
      <unknown-pk>
      <unknown-pk-class>java.lang.Long</unknown-pk-class>
      <field-name>personid</field-name>
      <column-name>PERSON_ID</column-name>
      <jdbc-type>LONG</jdbc-type>
      <sql-type>BIGSERIAL</sql-type>
      <auto-increment/>
      </unknown-pk>
      <entity-command name="postgresql-fetch-seq"/>



      public abstract class PersonBean implements EntityBean {
      
       public Long ejbCreate() throws javax.ejb.CreateException{
      
       return null;
       }
      



      But that I get, when call create() method
      Could not create entity:java.sql.SQLException: ERROR: null value in column "person_id" violates not-null constraint

      What I do wrong?

        • 1. Re: PostgreSQL key generation
          eric es Newbie

          Hi,

          I use the eclipse IDE / lomboz plugin / XDoclet combination to create my Bean classes. So I have a lot XDoclet and ejb comment for generating the actual bean classes. There's pretty much to setup this but if you send me an email I can send you some example code and deployement descriptors. my email: eric at cdls dot nl. btw: I have this working with PostgreSQL 7.4.7, I did not test with PostgreSQL 8...

          Greetings,
          Eric