liveBook · Manning

Joined inheritance strategy

As explained in Java Persistence with Spring Data and Hibernate epub

A joined inheritance strategy maps each class in an inheritance hierarchy to its own relational table, linking subclass rows to superclass rows through shared primary and foreign keys.

The joined inheritance strategy maps every class in an entity hierarchy to its own relational table. A subclass row shares its primary key with the superclass row, while a foreign key preserves the relationship. Retrieving a subclass requires joining its table with the superclass table. section 7.4

Mapping BillingDetails and its subclasses

Annotate the root entity with @Inheritance(strategy = InheritanceType.JOINED). BillingDetails maps to BILLINGDETAILS; BankAccount maps its declared fields to BANKACCOUNT, and CreditCard maps its fields to CREDITCARD. The subclasses inherit the identifier, so an explicit @PrimaryKeyJoinColumn is optional when the key names match. Each subclass key also references BILLINGDETAILS.ID. section 7.4

Unlike discriminator-based single-table mapping, JOINED requires no discriminator. Hibernate identifies concrete subclasses by checking joined subclass rows; polymorphic queries commonly use outer joins and CASE expressions, while concrete subclass queries use an inner join. section 7.4

Use JOINED when the relational model benefits from normalized tables and strong constraints.

  • Prefer it when subclasses declare many non-optional properties and differ mainly in the data they hold. section 7.7
  • Expect straightforward schema evolution and integrity-constraint definition; foreign keys to a subclass table can represent associations to that subclass. section 7.4
  • Evaluate real SQL execution plans when hierarchy width, depth, or join cost may make TABLE_PER_CLASS preferable. section 7.7
Figure 7.3 Mapping all classes of the hierarchy to their own tables

A hierarchy diagram makes the one-table-per-class layout and shared-key links immediately visible. section 7.4

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains annotations, shared keys, generated joins, concrete-type detection, and selection tradeoffs, but not execution-plan details.
Examples
Uses BillingDetails, BankAccount, CreditCard, repository queries, outer joins, inner joins, and CASE-based subclass detection.
What it assumes
Assumes entity inheritance, relational primary and foreign keys, and basic JPA annotations.
What you can do after
Apply it via JPA, Hibernate, and Spring Data repositories to map and query joined entity hierarchies.
How it connects
Connects polymorphic associations, single-table inheritance, table-per-class inheritance, foreign keys, normalization, and secondary tables.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.