Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
Previous |
Next |
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 |
|
|
Object-Relational Descriptors |
|
|
EIS DescriptorsFoot 2 |
|
|
XML Descriptors |
|
|
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").
To associate a descriptor with one or more primary keys, use this procedure:
Select a descriptor in the Navigator. Its properties appear in the Editor.
Click the Descriptor Info tab. The Descriptor Info tab appears.
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. |
You can use Java to configure primary keys for:
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.
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.