Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Configuring Sequencing at the Project Level

Sequencing allows TopLink to automatically assign the primary key or ID of an object when the object is inserted.

You configure TopLink sequencing at the project or session level to tell TopLink how to obtain sequence values: that is, what type of sequences to use.

In a CMP project, you do not configure a session directly: in this case, you must configure sequences at the project level. In a non-CMP project, you can configure a session directly: in this case, you can use a session-level sequence configuration to override project-level sequence configuration, on a session-by-session basis, if required (see "Configuring Sequencing at the Session Level").

Using TopLink Workbench (see "Using TopLink Workbench"), you can configure table sequencing (see "Table Sequencing") and native sequencing ("Native Sequencing With an Oracle Database Platform" and "Native Sequencing With a Non-Oracle Database Platform") and you can configure a preallocation size that applies to all sequences (see "Sequencing and Preallocation Size").

Using Java (see "Using Java"), you can configure any sequence type that TopLink supports ("Sequencing Types"). You can create any number and combination of sequences. You can create a sequence object explicitly or use the default sequence that the platform creates. You can associate the same sequence with more than one descriptor and you can configure a separate preallocation size for each descriptor's sequence.

If you are migrating a BEA WebLogic CMP application to OC4J and TopLink persistence (see "Migrating BEA WebLogic Persistence to OC4J TopLink Persistence"), the TopLink migration tool does not migrate BEA WebLogic single column sequence tables to TopLink unary sequence tables (see "Unary Table Sequencing"). After migration, you must manually configure your project to use TopLink unary sequence tables if your application originally used single column sequence tables in BEA WebLogic.

After configuring the sequence type at the project (or session) level, to enable sequencing, you must configure a descriptor with a sequence field and a sequence name (see "Configuring Sequencing at the Descriptor Level").

For more information about sequencing, see "Understanding Sequencing in Relational Projects".

Using TopLink Workbench

To specify the sequencing information for the project, use this procedure:

  1. Select the project object in the Navigator.

  2. Select the Sequencing tab in the Editor. The Sequencing tab appears.

    Figure 23-2 Sequencing Tab

    Description of Figure 23-2  follows
    Description of "Figure 23-2 Sequencing Tab"

Use this table to enter data in the following fields to configure the sequencing information:

Field Description
Preallocation Size Specify the default preallocation size (see "Sequencing and Preallocation Size"). Default is 50. The preallocation size you configure applies to all sequences.
Default Sequence Table Select this option to use table sequencing (see "Table Sequencing") with default sequence table name SEQUENCE, default sequence name field SEQ_NAME, and default sequence counter field SEQ_COUNT.
Native Sequencing Select this option to use a sequencing object (see "Native Sequencing With an Oracle Database Platform" or "Native Sequencing With a Non-Oracle Database Platform") created by the database platform. This option applies only to Oracle, Sybase, Microsoft SQL, and IBM Informix database platforms.
Custom Sequence Table Select this option to use table sequencing (see "Table Sequencing") with a sequence table name, sequence name field, and sequence counter field name that you specify.
    Name Specify the name of the sequence table.
    Name Field Specify the name of the column used to store the sequence name.
    Counter Field Specify the name of the column used to store the sequence count.

Using Java

Using Java, you can configure a project to use multiple, different sequences as Example 23-1 shows.

Example 23-1 Configuring Sequencing at the Project Level in Java

// Enable native sequencing for the project as the default. Configured the default preallocation size
project.getLogin().useNativeSequencing();
project.getLogin().setSequencePreallocationSize(50);

// Configure the EMP_SEQ to not use preallocation
DefaultSequence empSequence = new DefaultSequence("EMP_SEQ", 1);
project.getLogin().addSequence(empSequence);

// Configure the PROJ_SEQ to use a seperate sequence table
UnarySequence projSequence = new UnarySequence("PROJ_SEQ_TAB", "COUNTER");
project.getLogin().addSequence(projSequence);