Pattern: One Class One Table

Abstract

The pattern discusses how to map each classes in an inheritance hierarchy to a separate 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. Insert a Synthetic OID into each table to link derived classes rows with their parent table's corresponding rows.

Structure

Example Resolved

Mapping our running example to tables results in five tables - one for each class. A single instance of a SalariedEmployee is represented in three of these five tables.

Consequences

Implementation

Related Patterns

See also Representing Inheritance in a Relational Database [Bro+96] or see it as Concrete Inheritance Table at Martin Fowlers site.