Union subclass mapping stores each concrete subclass in its own table while duplicating superclass columns. In JPA, declare InheritanceType.TABLE_PER_CLASS on the abstract superclass; each subclass remains an entity, and the superclass must define the shared identifier. section 7.2
BillingDetails mapped with TABLE_PER_CLASS
An abstract BillingDetails entity can define the generated ID and owner fields, while CreditCard and BankAccount inherit those properties and persist to CREDITCARD and BANKACCOUNT. A repository can expose findByOwner and findAll operations for the hierarchy. section 7.2
Polymorphic query SQL
A query such as select bd from BillingDetails bd becomes a derived table assembled with UNION ALL. Each branch selects the columns for one concrete table, supplies nulls for fields belonging to the other subtype, and adds a discriminator literal such as 1 or 2. section 7.2
Listing 7.8 Mapping BillingDetails with TABLE_PER_CLASS
Path: Ch07/mapping-inheritance-tableperclass/src/main/java/com/manning /javapersistence/ch07/model/BillingDetails.java @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class BillingDetails { @Id @GeneratedValue(generator = “ID_GENERATOR”) private Long id; @NotNull private String owner; // . . . }
Use the superclass mapping listing to inspect the TABLE_PER_CLASS annotation, generated identifier, and shared owner property. section 7.2
The relational schema has no inheritance relationship between the tables; they merely repeat compatible columns. Choose this strategy when polymorphic access is absent or uncommon, or weigh it against SINGLE_TABLE and JOINED using hierarchy width, subtype attributes, and real SQL execution plans. section 7.2 section 7.7
