EAServer supports three mechanisms for key generation:
Using the Sybase identity datatype If you are using Sybase Adaptive Server Enterprise or Adaptive Server Anywhere, the mapped table uses the identity datatype for the primary key. The database manages the creation of new keys.
Using the Oracle sequence datatype If you are using an Oracle database, the main table uses an Oracle sequence for the primary key. The database manages the creation of new keys.
Using a key lookup table For any SQL database, you can use a single-row, single-integer-column table to generate key values. EAServer increments the key lookup value to generate new keys. If other processes or applications insert to the table, they must also use the key lookup table.
To configure the key generation mechanism and enable automatic key creation, set the keyGenerator attribute in the <persistentObject> Ant command that maps the database table to the entity bean. For example:
<target name="configure-user"> <setProperties component="ejb.components.example.CustomerInventory"> <persistentObject table="cust_inv" isolationLevel="RepeatableRead" dataSource=”myDB” keyGenerator=”key-gen-value” /> </setProperties> </target>
The the keyGenerator attribute takes the values listed in Table 4-2.
Value |
To specify |
---|---|
|
Oracle sequence seq-name |
|
Sybase style identity column |
|
Key generator table using the specified table, column name, and key increment batch size. For example, to specify a table named cust_key, using column next_id, and incrementing through 100 keys at a time, set the value to: cust_key.next_id += 100 Create the key lookup table if it does not exist in the database. EAServer does not create it automatically. |