InheritanceType.TABLE_PER_CLASS is a JPA inheritance mapping strategy in which every concrete entity class gets its own table, and that table contains columns for all inherited and declared fields. There are no joins to read a single subclass, but polymorphic queries against the parent type need a UNION across all the tables.
You select it with @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) on the root entity. Support for this strategy is optional in the JPA specification, although Hibernate and EclipseLink both implement it.
With this strategy, the hierarchy below produces one table for each concrete class and no table for the abstract root:
The resulting tables are:
The columns of Payment are repeated in each table. If the root class is concrete rather than abstract, it also gets its own table.
Because rows of different subclasses live in different tables but must share one id space, the identifier must be unique across the whole hierarchy. That rules out GenerationType.IDENTITY, since each table would count on its own and ids could collide.
Use one of these instead:
GenerationType.SEQUENCE with a shared sequence, which is the usual choice.GenerationType.TABLE with a shared table generator.@UuidGenerator in Hibernate 6.Querying a concrete subclass hits one table and is fast:
Querying the parent type is different:
The provider generates a UNION ALL of every subclass table, adding a discriminator literal so it knows which class to instantiate. This is acceptable for small hierarchies but gets slower with many subclasses or large tables. Associations that point to the base type, such as @ManyToOne Payment payment, are also awkward, because a foreign key cannot target several tables.
| Aspect | SINGLE_TABLE | JOINED | TABLE_PER_CLASS |
|---|---|---|---|
| Tables | One | One per class | One per concrete class |
| Polymorphic query | Fast, single scan | Joins | UNION ALL |
| Subclass query | Filter on discriminator | Join | Fastest, single table |
| Subclass columns nullable | Yes | No | No |
| Normalisation | Poor | Good | Duplicated columns |
IDENTITY ids | Yes | Yes | No |
| Foreign keys to base type | Yes | Yes | Not possible |
It suits hierarchies where you almost always work with one concrete type, subclasses have very different columns, and you rarely query the base type. If you need polymorphic queries and relationships to the parent type, choose SINGLE_TABLE for speed or JOINED for a normalised schema. Another option is @MappedSuperclass, which shares fields without making the parent a queryable entity at all.
No. The default is SINGLE_TABLE.
No. The table already identifies the class. Hibernate adds a literal discriminator only inside the generated UNION query.
Each table would generate its own ids, so two different subclasses could receive the same id, which breaks polymorphic lookups. Use a shared sequence or a UUID.
With @MappedSuperclass, the parent is not an entity, so you cannot query it or reference it in relationships. With TABLE_PER_CLASS it is a real entity that can be queried polymorphically.
TABLE_PER_CLASS gives each concrete class its own self-contained table, which makes single-class queries simple but polymorphic queries expensive. It forbids identity ids, duplicates parent columns, and is optional in the spec. Prefer SINGLE_TABLE or JOINED unless you rarely query through the base type.