user manual
Chapter 18: Generating Entity Bean Primary Keys 191
Chapter
18
Chapter 18Generating Entity Bean Primary
Keys
Each entity bean must have a unique primary key that is used to identify the
bean instance. The primary key can be represented by a Java class, which
must be a legal value type in RMI-IIOP. Therefore, it extends the
java.io.Serializable interface. It must also provide an implementation of the
Object.equals(Object other) and Object.hashCode() methods.
Normally, the primary key fields of entity beans must be set in the ejbCreate()
method. The fields are then used to insert a new record into the database.
This can be a difficult procedure, however, bloating the method, and many
databases now have built-in mechanisms for providing appropriate primary
key values. A more elegant means of generating primary keys is for the user
to implement a separate class that generates primary keys. This class can
also implement database-specific programming logic for generating primary
keys.
You may either generate primary keys by hand, use a custom class, or allow
the container to use the database tools to perform this for you. If you use a
custom class, implement the com.borland.ejb.pm.PrimaryKeyGenerationListener
interface, discussed in “Generating primary keys from a custom class” on
page 192. To use the database tools, you can refer to “Implementing primary
key generation by the CMP engine” on page 192 for information on the CMP
engine generating primary keys depending upon the database vendor.
Important For documentation updates, go to www.borland.com/techpubs/bes.










