Skip Headers

# Using Class Indicator Fields

Previous

Next

You can use a persistent attribute of a class to indicate which subclass should be instantiated. For example, in a relational descriptor, you can use a class indicator field in the root class table. The indicator field should not have an associated direct mapping unless it is set to read-only.

Note: If the indicator field is part of the primary key, define a write-only transformation mapping for the indicator field (see Configuring a Relational Transformation Mapping).

You can use strings or numbers as values in the class indicator field.

The root class descriptor must specify how the value in the class indicator field translates into the class to be instantiated.

One approach is to configure the root class descriptor with a class indicator dictionary: a collection of key-values that associates a simple key, stored in the class indicator field, with a class to instantiate. Table: Class Indicator Dictionary for the Vehicle Class illustrates the class indicator dictionary for the `Vehicle` class's subclasses as shown in Figure: Example Inheritance Hierarchy.

Class Indicator Dictionary for the Vehicle Class

Key | Value
--- | ---
F | FueledVehicle
N | NonFueledVehicle
C | Car
B | Bicycle

Another approach is to simply use the class name itself as the value stored in the class indicator field. This avoids having to define unique indicators for each class at the expense of a slightly larger key value (depending on the length of your class names).