Supporting Inheritance Using Multiple Tables

For subclasses that require additional attributes, 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 to determine the class of object to create, then uses the descriptor for that class to read from the subclass tables.

Figure 4-21 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 the secondary table.

Figure 4-21 Inheritance Using Separate Tables for Each Subclass


<p>This figure shows inheritance with separate tables.</p>


Note: Because NonFueledVehicle does not hold any attributes or relationships, it does not need a secondary table. For performance considerations, this design is inefficient because it requires multiple table fetching.

Related Topics

About TopLink Descriptors

Working with Descriptors
Working with Inheritance
Working with Descriptor Properties
Working with Advanced Properties

Using Inheritance with EJBs
Mapping Inherited Attributes in One Descriptor
Supporting Inheritance Using One Table

 

Copyright © 1997, 2004, Oracle. All rights reserved.