hibernate/hibernate-orm · error · AnnotationException
Embeddable class '%s' defines an inheritance hierarchy and c
Error message
Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'
What it means
Error "Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java:721
PropertyHolder holder,
MetadataBuildingContext context) {
assert embeddable.getDiscriminator() == null;
final var columns = new AnnotatedColumns();
columns.setPropertyHolder( holder );
columns.setBuildingContext( context );
discriminatorColumn.setParent( columns );
final var discriminatorColumnBinding = new BasicValue( context, embeddable.getTable() );
discriminatorColumnBinding.setAggregateColumn( embeddable.getAggregateColumn() );
embeddable.setDiscriminator( discriminatorColumnBinding );
discriminatorColumn.linkWithValue( discriminatorColumnBinding );
discriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() );
}
private static void validateInheritanceIsSupported(
PropertyHolder holder,
CompositeUserType<?> compositeUserType) {
if ( holder.isOrWithinEmbeddedId() ) {
throw new AnnotationException( String.format(
"Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@EmbeddedId'",
holder.getClassName()
) );
}
else if ( holder.isInIdClass() ) {
throw new AnnotationException( String.format(
"Embeddable class '%s' defines an inheritance hierarchy and cannot be used in an '@IdClass'",
holder.getClassName()
) );
}
else if ( compositeUserType != null ) {
throw new AnnotationException( String.format(
"Embeddable class '%s' defines an inheritance hierarchy and cannot be used with a custom '@CompositeType'",
holder.getClassName()
) );
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Use an embeddable class without an inheritance hierarchy as the @EmbeddedId.
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/5950dc960c4d8a0e.
Report an issue: GitHub.