user manual
192 BES Developer’s Guide
Generating primary keys from a user class
Generating primary keys from a user class
With enterprise beans, the primary key is represented by a Java class
containing the unique data. This primary key class can be any class as long as
that class is a legal value type in RMI-IIOP, meaning it extends the
java.io.Serializable interface. It must also provide an implementation of the
Object.equals(Object other) and Object.hashCode() methods, two methods
which all Java classes inherit by definition.
Generating primary keys from a custom class
To generate primary keys from a custom class, you must write a class that
implements the com.borland.ejb.pm.PrimaryKeyGenerationListener interface.
Note this is a new interface for generating primary keys. In previous versions of
Borland Enterprise Server, this class was
com.inprise.ejb.cmp.PrimaryKeyGenerator. This interface is still supported, but
Borland recommends using the newer interface when possible.
Next, you must inform the container of your intention to use your custom class
to generate primary keys for your entity beans. To do this, you set a table
property primaryKeyGenerationListener to the class name of your primary key
generator.
Implementing primary key generation by the CMP engine
Primary key generation can also be implemented by the CMP engine. Borland
provides four properties to support primary key generation using database
specific features. These properties are:
■
getPrimaryKeyBeforeInsertSql
■
getPrimaryKeyAfterInsertSql
■
ignoreOnInsert
■
useGetGeneratedKeys
All of these properties are table properties except ignoreOnInsert, which is a
column property. Setting table and column properties is discussed here.
Oracle Sequences: using getPrimaryKeyBeforeInsertSql
The property getPrimaryKeyBeforeInsertSql is typically used in conjunction with
Oracle Sequences. The value of this property is a SQL statement used to
select a primary key generated from a sequence. For example, the property
could be set to:
SELECT MySequence.NEXTVAL FROM DUAL










