DB2 and Identity column
pvanhout Oct 14, 2005 10:48 PMDB2 8.1
JBoss 4.0.2
Has anyone got JDBCDB2IdentityValLocalCreateCommand to work with a DB2 table with Identity columns?
My tables are already created. When using the JDBCDB2IdentityValLocalCreateCommand entity command I get the error "Could not create entity:com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -407, SQLSTATE: 23502, SQLERRMC: TBSPACEID=2, TABLEID=33, COLNO=1".
This error means that the statement cannot insert a null value into a column that is defined as NOT NULL.
My class-level Xdoclet is as follows:
* @ejb.bean name="PalletItem"
* display-name="PalletItem"
* description="PalletItem EJB"
* jndi-name="psv.ejb.PalletItem"
* local-jndi-name="psv.ejb.PalletItemLocalHome"
* type="CMP"
* cmp-version="2.x"
* view-type="local"
* primkey-field="ID"
*
* @ejb.persistence table-name="OVERIFY.PALLETITEM"
*
* @jboss.entity-command name="db2-identity"
My primary key field code is as follows:
/**
* @ejb.interface-method view-type="local"
* @ejb.persistence column-name="id"
* @ejb.pk-field
* @jboss.persistence auto-increment="true"
*
* @return
*/
public abstract Long getID();
/**
* @ejb.interface-method view-type="local"
*
* @return
*/
public abstract void setID(Long id);
The merge file jbosscmp-jdbc-entity-commands.xml looks like:
<entity-commands>
<entity-command name="db2-identity" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCDB2IdentityValLocalCreateCommand"/>
</entity-commands>
This creates a jbosscml-jdbc.xml file with the following entity and entity-commands entries:
<ejb-name>PalletItem</ejb-name>
<table-name>OVERIFY.PALLETITEM</table-name>
<cmp-field>
<field-name>ID</field-name>
<column-name>id</column-name>
<auto-increment/>
</cmp-field>
<cmp-field>
<field-name>palletNumber</field-name>
<column-name>pallet_nbr</column-name>
</cmp-field>
<cmp-field>
<field-name>quantityScanned</field-name>
<column-name>qty_scanned</column-name>
</cmp-field>
<cmp-field>
<field-name>quantityToShip</field-name>
<column-name>qty_to_ship</column-name>
</cmp-field>
<entity-command name="db2-identity">
</entity-command>
<entity-commands>
<entity-command name="db2-identity" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCDB2IdentityValLocalCreateCommand"/>
</entity-commands>
Can anyone tell me what I am doing wrong? Alternatively, if someone can show me how to use a DB2 sequence instead of an identity field, I might be able to persuade the DBA to go that route.