Chapter 9. Inheritance

Table of Contents

Use Case
Overview on mapping approaches
Single Table
Joined Inheritance
Joined Inheritance with Discriminator
Mixing Single table and Joined
Union Inheritance
XML Includes
Mapped Super Class

We will explore mapping Java inheritance structures to the database.

Use Case

Our use case is about mice. There is a parent class Mouse and two sub classes LibraryMouse, KitchenMouse. As the name indicates one lives in a library and the other one in the kitchen.


Hibernate allows to map inheritance structures to database table and it provides a number of approaches to do this. Not all approaches are support by XML mappings and not all by annotations. Source code for the samples can be found in the package de.laliluna.inheritance in the project mapping-examples-xml and mapping-examples-annotation.