0 Replies Latest reply on Oct 3, 2003 11:14 AM by pkrishna

    Problem creating EJB because of auto-generation of PK

    pkrishna

      I have 2 EJBs both associated with each other through CMR. One of the EJBs has built in primary key field (by using the <primkey-field>id</primkey-field> in the ejb-jar.xml) while the other relies on auto-generation of primary key. The create() method of this EJB does not take any parameter. After doing some search in the forum, I understand to support auto-generation of primary key for the 2nd EJB, I have to include the following in the default section of jbosscmp-jdbc.xml:

      <unknown-pk>
      <unknown-pk-class>java.lang.Integer</unknown-pk-class>
      <field-name>id</field-name>
      <column-name>id</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER</sql-type>
      <auto-increment/>
      </unknown-pk>
      <entity-command name="get-generated-keys"/>

      I also understood that for this EJB I need to a section like the one below:

      <cmp-field>
      <field-name>id</field-name>
      <auto-increment/>
      </cmp-field>
      I am using a firebird driver . In the standardjbosscmp-jdbc.xml, I added an element

      <auto-increment-template>?1</auto-increment-template> in the type-mapping section for this driver. BTW, I am not sure if this is the correct syntax. I just cut and pasted from the another section.

      The EJBs deplyed fine and created the necessary tables but when I went an EJB which required an ID, the firebird driver threw an exception:

      INFO: Loading person with id = '1'
      2003-10-03 10:47:47,392 ERROR [org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBC30GeneratedKeysCreateCommand.PersonBean] Could not create entity
      java.sql.SQLException: not yet implemented
      at org.firebirdsql.jdbc.FBConnection.prepareStatement(FBConnection.java:167)
      at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:281)

      This was working fine till I had the section on unknownpk. Could somebody tell me if I have configured something wrong in jbosscmp-jdbc.xml.