hibernate/hibernate-orm · error · AnnotationException
Entity class '<className>' is annotated '@DiscriminatorColum
Error message
Entity class '<className>' is annotated '@DiscriminatorColumn' but it is not the root of the entity inheritance hierarchy
What it means
Error "Entity class '<className>' is annotated '@DiscriminatorColumn' but it is not the root of the entity inheritance hierarchy" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java:1040
}
}
/**
* Process all discriminator-related metadata per rules for "single table" inheritance
*/
private AnnotatedDiscriminatorColumn processSingleTableDiscriminatorProperties(InheritanceState inheritanceState) {
final var discriminatorColumn = annotatedClass.getAnnotationUsage( DiscriminatorColumn.class, modelsContext() );
final var discriminatorFormula = getOverridableAnnotation( annotatedClass, DiscriminatorFormula.class, context );
if ( !inheritanceState.hasParents()
|| annotatedClass.hasAnnotationUsage( Inheritance.class, modelsContext() ) ) {
return buildDiscriminatorColumn( discriminatorColumn, discriminatorFormula,
null, DEFAULT_DISCRIMINATOR_COLUMN_NAME, context );
}
else {
// not a root entity
if ( discriminatorColumn != null ) {
throw new AnnotationException( "Entity class '" + annotatedClass.getName()
+ "' is annotated '@DiscriminatorColumn' but it is not the root of the entity inheritance hierarchy");
}
if ( discriminatorFormula != null ) {
throw new AnnotationException( "Entity class '" + annotatedClass.getName()
+ "' is annotated '@DiscriminatorFormula' but it is not the root of the entity inheritance hierarchy");
}
return null;
}
}
/**
* Process all discriminator-related metadata per rules for "joined" inheritance, taking
* into account {@value AvailableSettings#IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS}
* and {@value AvailableSettings#IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS}.
*/
private AnnotatedDiscriminatorColumn processJoinedDiscriminatorProperties(InheritanceState inheritanceState) {
final var modelContext = modelsContext();
View on GitHub (pinned to fad1729dce)
Solutions
- Move @DiscriminatorColumn to the root class of the entity inheritance hierarchy.
When it happens
Trigger: An annotation restricted to the root of an inheritance hierarchy is placed on a subclass (or the hierarchy rules are otherwise violated).
Common situations: SINGLE_TABLE/JOINED hierarchies where @Table, @DiscriminatorColumn, @DiscriminatorFormula, @Cache, @Immutable, @Id or @Version are declared on the wrong class of the hierarchy.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/0a68345f18c537f7.
Report an issue: GitHub.