user manual

Chapter 18: Generating Entity Bean Primary Keys 193
Implementing primary key generation by the CMP engine
The CMP engine would execute this SQL and then extract the appropriate
value from the ResultSet. This value will then be used as the primary key
when performing the subsequent INSERT. The extraction from the ResultSet is
based on the primary key's type
SQL Server: using getPrimaryKeyAfterInsertSql and
ignoreOnInsert
Two properties need to be specified for cases involving SQL Server. The
getPrimaryKeyAfterInsertSql property specified the SQL to execute after the
INSERT has been performed. As above, the CMP engine extracts the primary
key from the ResultSet based on the primary key's type. The property
ignoreOnInsert must also be set to the name of the identity column. The CMP
engine will then know not to set that column in the INSERT.
JDataStore JDBC3: using useGetGeneratedKeys
Borland's JDataStore supports the new JDBC3 method
java.sql.Statement.getGeneratedKeys(). This method is used to obtain primary
key values from newly inserted rows. No additional coding is necessary, but
note that this method is unsupported in other databases and is recommended
for use only with Borland JDataStore. To use this method, set the boolean
property useGetGeneratedKeys to True.
Automatic primary key generation using named sequence
tables
A named sequence table is used to support auto primary key generation when
the underlying database (such as Oracle SEQUENCE) and the JDBC driver
(AUTOINCREMENT in JDBC 3.0) do not support key generation . The named
sequence table allows you to specify a table that holds a key to use for primary
key generation. The container uses this table to generate the keys.
The table must contain a single row with a single column
To use the name sequence table your table must have a single row with a
single column that is an integer (for the sequence values). You must create a
table with one column named "SEQUENCE" with any initial value. For example:
CREATE TABLE TAB_A_SEQ (SEQUENCE int);
INSERT into TAB_A_SEQ values (10);
In this example key generation starts from value 10.
To enable this feature, set it in <column-properties> in ejb-borland.xml:
<table-properties>
<table-name>TABLE_A</table-name>
<column-properties>
<column-name>ID</column-name>