CHAPTER 4

image

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 necessarily have its own separate table.

Hibernate provides four strategies for mapping an inheritance hierarchy:

  • Table per class hierarchy ...

Get Hibernate Recipes: A Problem-Solution Approach, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.