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 Primary Keys

A primary key is a unique identifier (made up of one or more persistent attributes) that distinguishes one instance of a class from all other instances of the same type. You use primary keys to define relationships and to define queries.

For the descriptors shown in Table 28-3, you must configure a primary key and you must ensure that your class contains one or more persistent fields suitable for this purpose.

Table 28-3 summarizes which descriptors support primary keys.

Table 28-3 Descriptor Support for Primary Keys

Descriptor Using TopLink Workbench
Using Java

Relational DescriptorsFoot 1 

Supported.


Supported.


Object-Relational Descriptors

Unsupported.


Supported.


EIS DescriptorsFoot 2 

Supported.


Supported.


XML Descriptors

Unsupported.


Unsupported.



Footnote 1 Relational class descriptors only (see "Relational Class Descriptors").

Footnote 2 EIS root descriptors only (see "EIS Root Descriptors").

For a relational class (non-aggregate) descriptor, choose any unique database field or set of unique database fields from the descriptor's associated table (see "Configuring Associated Tables").

For an EIS root descriptor (see "Configuring an EIS Descriptor as a Root or Composite Type"), choose any unique attribute or text node or set of unique attributes or text nodes from the descriptor's schema context (see "Configuring Schema Context for an EIS Descriptor").

Using TopLink Workbench

To associate a descriptor with one or more primary keys, use this procedure:

  1. Select a descriptor in the Navigator. Its properties appear in the Editor.

  2. Click the Descriptor Info tab. The Descriptor Info tab appears.

    Figure 28-1 Descriptor Info Tab, Primary Key Options

    Description of Figure 28-1  follows
    Description of "Figure 28-1 Descriptor Info Tab, Primary Key Options"

Use this table to enter data in each field on the descriptor's Descriptor Info tab to specify the primary key(s):

Field Description
Primary Keys To specify the primary keys for the table, click Add in order to do the following:

To remove a primary key, select the key and click Remove.


Using Java

You can use Java to configure primary keys for:

Relational Projects

Use ClassDescriptor method addPrimaryKeyFieldName to specify the primary key field of the descriptor's table. This should be called for each field that makes up the primary key of the table.

If the descriptor has more than one table, and all other tables have the same primary key, use the ClassDescriptor method addPrimaryKeyFieldName to specify the the primary key in the first table.

If the descriptor has more than one table, and each table has a different primary key, use ClassDescriptor method addMultipleTablePrimaryKeyFieldName to map the primary key field names in each table.

EIS Projects

Use EISDescriptor method addPrimaryKeyFieldName to specify the primary key field of the descriptor's class. Call this method for each field that makes up the primary key.