Chapter 4. Inheritance and Custom Mapping

Inheritance, polymorphic associations, and polymorphic queries are supported by entities. The JPA specification says that both concrete and abstract classes can be entities and can be mapped with the Entity annotation. Non-entity classes and entity classes can extend each other. Hibernate provides the MappedSuperClass annotation (@MappedSuperclass) to enable inheritance mapping and to let you map abstract or concrete entity subclasses. The mapped superclass doesn't have its own separate table.

Hibernate provides four strategies for mapping an inheritance hierarchy:

  • Table per class hierarchy: The class hierarchy is represented in one table. A discriminator column identifies the type and the subclass.

  • Table ...

Get Hibernate Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.