hibernate/hibernate-orm · error · AnnotationException
Embeddable subclass '%s' defines the same discriminator valu
Error message
Embeddable subclass '%s' defines the same discriminator value as '%s
What it means
Error "Embeddable subclass '%s' defines the same discriminator value as '%s" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java:778
}
subclass = superClass;
}
return classElements;
}
private static void collectSubclassElements(
AccessType propertyAccessor,
MetadataBuildingContext context,
ClassDetails superclass,
List<PropertyData> classElements,
BasicType<?> discriminatorType,
Map<Object, String> discriminatorValues,
Map<String, String> subclassToSuperclass) {
for ( var subclass : context.getMetadataCollector().getEmbeddableSubclasses( superclass ) ) {
// collect the discriminator value details
final String old = collectDiscriminatorValue( subclass, discriminatorType, discriminatorValues );
if ( old != null ) {
throw new AnnotationException( String.format(
"Embeddable subclass '%s' defines the same discriminator value as '%s",
subclass.getName(),
old
) );
}
final String put = subclassToSuperclass.put( subclass.getName().intern(), superclass.getName().intern() );
assert put == null;
// collect property of subclass
final var superContainer = new PropertyContainer( subclass, superclass, propertyAccessor );
addElementsOfClass( classElements, superContainer, context, 0 );
// recursively do that same for all subclasses
collectSubclassElements(
propertyAccessor,
context,
subclass,
classElements,
discriminatorType,
discriminatorValues,View on GitHub (pinned to fad1729dce)
Solutions
- Give each embeddable subclass a distinct @DiscriminatorValue.
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/a25925b8f2f62fd7.
Report an issue: GitHub.