The SINGLE_TABLE inheritance strategy maps an entire entity class hierarchy to one database table. A discriminator column tells the persistence provider which subclass each row represents. It needs no joins, so polymorphic queries are fast, but every subclass column must be nullable and the table grows wide when subclasses differ a lot.
SINGLE_TABLE is the default strategy in Jakarta Persistence (JPA) when you put @Inheritance on a root entity without arguments.
With this strategy the table contains the columns of the root class plus the columns of every subclass. A row for a Car fills the car columns and leaves the bike columns NULL, and the other way around. The discriminator column, DTYPE by default, stores a value such as Car or Bike.
| id | dtype | name | doors | has_basket |
|---|---|---|---|---|
| 1 | Car | Roadster | 2 | NULL |
| 2 | Bike | City bike | NULL | true |
The annotations are in the jakarta.persistence package since Jakarta EE 9 (Spring Boot 3 and Hibernate 6). On older stacks (Spring Boot 2) they live in javax.persistence.
@Inheritance goes on the root entity only.@DiscriminatorColumn sets the column name and type. Defaults are DTYPE and STRING.@DiscriminatorValue sets the value for each class. The default is the entity name.Hibernate generates a single table roughly like this:
Polymorphic queries need no joins:
The first query reads the table once. The second adds where vehicle_type = 'CAR' automatically. Loading a Vehicle by id also needs just one row lookup, because the discriminator decides the concrete class.
Advantages:
Drawbacks:
NOT NULL for them. Use check constraints or application validation to compensate.| Strategy | Tables | Joins | Strong constraints | Best for |
|---|---|---|---|---|
SINGLE_TABLE | One | None | No (nullable subclass columns) | Small, similar subclasses; read speed matters |
JOINED | One per class | Yes | Yes | Normalized data, very different subclasses |
TABLE_PER_CLASS | One per concrete class | Unions for polymorphic queries | Yes | Rare; few polymorphic queries |
TABLE_PER_CLASS is optional for providers in the JPA specification and usually performs poorly for polymorphic queries, so most projects choose between SINGLE_TABLE and JOINED.
doors is not null when vehicle_type = 'CAR'.@DiscriminatorValue rather than relying on class names that may be renamed.@DiscriminatorFormula to compute the discriminator from existing columns, which is Hibernate-specific.JOINED or to composition.Yes. If a root entity has subclasses and no @Inheritance annotation, the provider uses SINGLE_TABLE with a DTYPE discriminator column.
Not at the column level, because rows of other subclasses must store NULL there. Enforce it with a check constraint that depends on the discriminator, or in the application.
Usually for reads and writes of the hierarchy, because no join is needed. The difference matters most on deep hierarchies and large tables, so measure with your own data.
The JPA specification does not require support for mixing, and Hibernate only supports it in limited ways. Use one strategy per hierarchy.
SINGLE_TABLE stores a whole entity hierarchy in one table and separates types with a discriminator column. It is fast and simple, at the cost of nullable subclass columns and sparse rows. Choose it for small, similar subclasses, and pick JOINED when you need strict constraints or the subclasses differ widely.