0 Replies Latest reply on May 8, 2003 4:41 AM by Dmitry Mozheyko

    auto-increment with FirebirdSQL

    Dmitry Mozheyko Novice

      JBOSS-3.2.1
      FirebirdSQL 1.0.796

      #######################
      createtable.sql
      #######################
      ...
      create table sometable(
      code integer not null primary key,
      name varchar(64)
      );

      create generator some_gen;
      ...
      #######################
      jbosscmp-jdbc.xml:
      #######################
      ...

      <ejb-name>SomeBean</ejb-name>
      <table-name>sometable</table-name>

      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      </cmp-field>
      <unknown-pk>
      <unknown-pk-class>java.lang.Integer</unknown-pk-class>
      <field-name>code</field-name>
      <column-name>code</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER</sql-type>
      <auto-increment/>
      </unknown-pk>

      <entity-command name="pk-sql">
      SELECT GEN_ID( SOME_GEN, 1) FROM RDB$DATABASE
      </entity-command>


      ...
      #######################
      ejb-jar.xml:
      #######################
      ...

      <ejb-name>SomeBean</ejb-name>
      <local-home>org.some.SomeHome</local-home>
      org.some.Some
      <ejb-class>org.some.SomeBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>somes</abstract-schema-name>
      <cmp-field><field-name>code</field-name></cmp-field>
      <cmp-field><field-name>name</field-name></cmp-field>
      <primkey-field>code</primkey-field>
      ...
      #######################
      SomeBean.java
      #######################
      ...
      public abstract class SomeBean implements EntityBean
      {
      EntityContext context;

      public abstract Integer getCode();
      public abstract void setCode( Integer _code);
      public abstract String getName();
      public abstract void setName( String p);
      public Integer ejbCreate( String p) throws CreateException{
      setCode( ( Integer)context.getPrimaryKey());
      setName( p);
      System.out.println( "ejbCreate: Code = " + getCode());
      return null;
      }
      ...

      if i call home.create( "somestring");

      14:21:30,767 INFO [STDOUT] ejbCreate: Code = null
      14:21:30,811 ERROR [WorkBean] Could not create entity
      org.firebirdsql.jdbc.FBSQLException: GDS Exception. validation error for column CODE, value "*** null ***"
      at org.firebirdsql.jdbc.FBPreparedStatement.internalExecute(FBPreparedStatement.java:425)
      at org.firebirdsql.jdbc.FBPreparedStatement.executeUpdate(FBPreparedStatement.java:136)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.insertEntity(JDBCCreateEntityCommand.java:321)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCPkSqlCreateCommand.execute(JDBCPkSqlCreateCommand.java:94)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:569)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:225)
      ...

      What steps I should make use an auto-in
      crement primary key ?