Setting Persistence/General subtab properties  Creating database tables

Chapter 27: Creating Entity Components

Enabling automatic key generation

If automatic key generation is enabled, keys are created automatically for every row inserted in the table. If you are mapping container-managed fields to multiple tables, automatic key generation applies only to the main table, specified on the Persistence/General subtab.

StepsSpecifying the key type for EJB CMP entity beans

There are two options for the primary key type when using automatic key generation in EJB and Java components:

Specify the key type in the EAServer Manager Component Properties dialog box as follows:

  1. On the Persistence/General subtab, set the Primary Key field to the Java class name used in your code. EAServer Manager saves the setting as the IDL type, and you will see the IDL type after you close and reopen the Component Properties dialog box.

    Java key type

    IDL key type

    java.lang.Object

    XDT::Integer

    java.lang.Integer

    CtsComponents::LongValue

    Other integral types

    The corresponding CtsComponents value structure

  2. Regenerate stubs and skeletons for the component if you have changed the primary key type.

StepsChoosing the key generation mechanism

  1. EAServer supports three mechanisms for key generation:

StepsConfiguring key generation to use the Sybase identity datatype

  1. Use the Advanced tab to set the property com.sybase.jaguar.component.generateKey to true. The default is false.

  2. In the Persistence/Field Mappings tab, verify that the key field is mapped to the Sybase identity type or a compatible type.

  3. Use the Advanced tab to verify that the property com.sybase.jaguar.component.db.sequence is not set, or set to no value.

StepsConfiguring key generation using the Oracle sequence datatype

  1. Use the Advanced tab to set the property com.sybase.jaguar.component.generateKey to true. The default is false.

  2. In the Persistence/Field Mappings tab, verify that the key field is mapped to the Oracle sequence type or a compatible type.

  3. If using an existing table or a table that you create yourself (rather than relying on autocreation by EAServer), use the Advanced tab to set the component property com.sybase.jaguar.component.db.sequence. This property specifies the name of the Oracle sequence to use. The default is:

    table_keys
    

    Where table is the main table name specified on the Persistence/General subtab.

StepsConfiguring key generation to use a key lookup table

  1. Use the Advanced tab to set the property com.sybase.jaguar.component.generateKey to true. The default is false.

  2. In the Persistence/Field Mappings tab, verify that the key field is mapped to an integer type that is compatible with the type used in the lookup table–see “Setting field-mapping properties”.

  3. Use the Advanced tab to set the component property com.sybase.jaguar.component.db.sequence to a value:

    table.column += key_use_rate
    

    or

    table += key_use_rate
    

    Where:

  4. Create the key lookup table if it does not exist in the database.

StepsOverriding the use of native identity types

  1. If you are using Sybase or Oracle, you can force the use of a key lookup table rather than the Sybase identity or Oracle sequence datatypes. To do so, set the com.sybase.jaguar.component.db.sequence. property and specify a key use rate as described in “Configuring key generation to use a key lookup table”. If the value of this property contains “+=”, EAServer uses a key lookup table regardless of the database type.





Copyright © 2005. Sybase Inc. All rights reserved. Creating database tables