Skip Headers

# Query Keys and Expressions

Previous

Next

A query key is a schema-independent alias for a database field name.

Query keys are supported in relational database projects only.

Query keys are generated automatically for all direct and relationship mappings. The name of the query key is the class attribute name.

For more information on how query keys are created and modified, see "Configuring Query Keys".

Example: Using an Automatically Generated Query Key in an Expression illustrates how to use the query key `firstName` for the corresponding directly mapped `Employee` attribute.

Using an Automatically Generated Query Key in an Expression

    Vector employees = session.readAllObjects(Employee.class,
      new ExpressionBuilder().get("firstName").equal("Bob"));

Example: Using a One-to-One Query Key in an Expression illustrates how to use a one-to-one query key within the TopLink expression framework.

Using a One-to-One Query Key in an Expression

    ExpressionBuilder employee = new ExpressionBuilder();
    Vector employees = session.readAllObjects(Employee.class,
      employee.get("address").get("city").equal("Ottawa"));

To access one-to-many and many-to-many query keys that define a distinct join across a collection relationship, use `Expression` method `anyOf`.