Pattern: One Inheritance Path One Table

Abstract

The pattern demonstrates a way to map all attributes occurring in an inheritance path to a single database table.

Problem

How do you map an inheritance hierarchy of classes to database tables?

Forces

The forces are identical to those discussed with the One Inheritance Tree One Table pattern.

Solution

Map the attributes of each class to a separate table. To a classes’ table add the attributes of all classes the class inherits from.

Structure

Example Resolved

Mapping our running example to tables results in five tables - one for each class. An instance of a SalariedEmployee is represented in one of these five tables. The SalariedEmployee is mapped as follows:

Consequences

·         Database load on root tables: There are no bottlenecks in tables near to the root of the inheritance hierarchy. Accessing an object exactly locks one table.

Implementation

Related Patterns

See also Representing Inheritance in a Relational Database [Bro+96]. See the same thing as Class Inheritance Table at Martin Fowlers site.