Skip Headers

# Configuring Inheritance Expressions for a Parent (Root) Class Descriptor

Previous

Next

If your class uses inheritance (see "Understanding Descriptors and Inheritance") with a class extraction method (see "Using Class Extraction Methods") you must provide TopLink with expressions to correctly filter sibling instances for all classes that share a common table.

Table: Descriptor Support for Inherited Attribute Mapping Configuration summarizes which descriptors support inheritance expression configuration.

Descriptor Support for Inheritance Expression Configuration

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

Figure: Example Inheritance Hierarchy shows a typical inheritance hierarchy. In this example, instances of both `Person` and `Student` are stored in the same `PERSON` table as Figure: PERSON Table shows: an instance of `Person` has a `null` value for `STUDENT_NUMBER`. Instances of `Company` are stored in a separate `COMPANY` table.

Example Inheritance Hierarchy

Description of "Example Inheritance Hierarchy"

PERSON Table

Description of "PERSON Table"

Queries on inheritance classes that share a common table, such as `Person` and `Student`, must filter out their sibling instances. TopLink performs this filtering using the `Expression` instances returned by the descriptor's `InheritancePolicy` methods `getOnlyInstancesExpression` and `getWithAllSubclassesExpression`.

Queries on a class that has its own table for its specific data, such as `Company`, and does not share this table with any sibling classes, do not require these expressions.

If you use a class indicator type field (see "Using Class Indicator Fields"), TopLink automatically generates the required expressions.

If you use a class extraction method (see "Using Class Extraction Methods"), you must provide TopLink with an expressions to correctly filter sibling instances for all classes that share a common table.

For concrete classes, you must define an only- instances expression.

For branch classes, you must define a with-all-subclasses expression.

When TopLink queries for a leaf class, it uses the only- instances expression to filter out any sibling classes.

When TopLink queries for a root or branch class whose subclasses do not define their own tables, it uses the with-all-subclasses expression. This is also the case when a subclass view is used (see "Configuring Reading Subclasses on Queries").

When querying for a root or branch class that has subclasses that span multiple tables, a query is performed for each concrete class in the inheritance hierarchy using the only- instances expression to filter sibling classes.

When a class extraction method is used the only-instances expression is used to determine if a class is concrete. If a class does not require an only instances expression, do not enable reading subclasses on queries (see "Configuring Reading Subclasses on Queries"), otherwise TopLink will assume that the class has no instances and it will skip that class on queries.

For more information about inheritance expressions, see "Specifying Expressions for Only-Instances and With-All-Subclasses".