Skip Headers

# Multitable Inheritance

Previous

Next

In this example, you store classes with multiple levels of inheritance in multiple tables to optimize database storage space.

In the inheritance hierarchy shown in Figure: Example Inheritance Hierarchy, for subclasses that require additional attributes, you use multiple tables instead of a single superclass table. This optimizes storage space because there are no unused fields in the database. However, this may affect performance because TopLink must read from more than one table before it can instantiate the object. TopLink first looks at the class indicator field (see "Specifying a Class Indicator") to determine the class of object to create, then uses the descriptor for that class to read from the subclass tables.

Figure: Inheritance Using Separate Tables for Each Subclass illustrates the TopLink implementation of the `FUELEDVHCL`, `CAR`, and `BICYCLE` tables. All objects are stored in the `VEHICLE` table. `FueledVehicle`, `Car`, and `Bicycle` information are also stored in secondary tables. Note that because the `NonFueledVehicle` class does not hold any attributes or relationships, it does not need a secondary table.

Inheritance Using Separate Tables for Each Subclass

Description of "Inheritance Using Separate Tables for Each Subclass"

Note: . In general, using multitable inheritance is inefficient because it can require excessive joins and multiple table fetching.