advancedEntity Mapping — @Entity, @Id, Inheritance & Composite Keys

What are the three JPA inheritance mapping strategies, and what's the core tradeoff between them?

Single Table (one table, a discriminator column, nullable columns for subtype-specific fields — fastest, no joins, but sparse columns), Joined (one table per subtype joined back to a base table — normalized, but requires a join to reconstruct a full entity), and Table Per Class (each subtype fully independent — no joins for one subtype, but polymorphic queries across all subtypes need a UNION).

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why does GenerationType.IDENTITY prevent Hibernate from batching inserts efficiently?← Back to all Spring Data JPA & Hibernate Mastery questions