Skip Headers

# Configuring Interface Query Keys

Previous

Next

A query key is a schema independent alias for a database field name. For more information about query keys, see "Configuring Query Keys".

Interface descriptors (see "Relational Interface Descriptors") are defined only with query keys that are shared among their implementors. In the descriptor for an interface, only the name of the query key is specified.

In each implementor descriptor, the key must be defined with the appropriate field from one of the implementor descriptor's tables.

This allows queries and relationship mappings to be defined on the interface using the query key names.

Interface query keys are supported in relational database projects only.

Table: Descriptor Support for Query Keys summarizes which descriptors support interface query keys.

Descriptor Support for Interface Query Keys

Descriptor | Using TopLink Workbench | Using Java
--- | --- | ---
Relational Descriptors |  |
Object-Relational Descriptors |  |
EIS Descriptors |  |
XML Descriptors |  |

Consider an `Employee` that contains a contact of type `Contact`. The `Contact` class is an interface with two implementors: `Phone` and `Email`. The `Phone` class has attributes `id` and `number`. The `Email` class has attributes `id` and `address`. Figure: Automatically Generated Query Keys for Phone and Email illustrates the generated keys:

Automatically Generated Query Keys for Phone and Email

Description of "Automatically Generated Query Keys for Phone and Email "

Both classes have an attribute, id, that is directly mapped to fields that have different names. However, a query key is generated for this attribute. For the `Contact` interface descriptor, you must indicate that the `id` query key must be defined for each of the implementors.

If either of the implementor classes did not have the `id` query key defined, TopLink Workbench flags that descriptor as deficient.

Now that a descriptor with a commonly shared query key has been defined for `Contact`, you can use it as the reference class for a variable one-to-one mapping (see "Using Queries on Variable One-to-One Mappings").

For example, you can now create a variable one-to-one mapping for the `contact` attribute of `Employee`. When you edit the foreign key field information for the mapping, you must match the `Employee` descriptor's tables to query keys from the `Contact` interface descriptor.