Inheritance relationships in JPA and Hibernate

Choosing a JPA inheritance strategy that supports polymorphism

Inheritance is a common pattern in object-oriented programming, but it's not easily replicated in a database. This Java tip shows you how to model inheritance relationships in JPA with Hibernate.

Learn the pros and cons of four different ORM inheritance strategies and get tips for choosing the one that best supports your application needs.

The inheritance pattern in ORM

Inheritance is an object-oriented pattern in which one class extends (or specializes) another class in order to borrow (or inherit) some of its functionality. For example, let's say we have a class named Car that represents all cars, including a make, model, and year. But now we want to create some more specialized types of car, such as SportsCar and SportUtilityVehicle. These cars would have all the features of the original Car class, but with some additional functionality. A SportsCar might need special parameters for designating speed. A SportsUtilityVehicle might need flags for seating and towing capacity.

To continue reading this article register now

How to choose a low-code development platform