hibernate/hibernate-orm · error · AnnotationException
Invalid class annotated both '@Embeddable' and '@MappedSuper
Error message
Invalid class annotated both '@Embeddable' and '@MappedSuperclass': '{}' What it means
Error "Invalid class annotated both '@Embeddable' and '@MappedSuperclass': '{}'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:1252
public AnnotatedClassType addClassType(ClassDetails clazz) {
final var type = getAnnotatedClassType( clazz );
annotatedClassTypeMap.put( clazz.getName(), type );
return type;
}
private static AnnotatedClassType getAnnotatedClassType(ClassDetails clazz) {
if ( isEntity( clazz) ) {
if ( isEmbeddable( clazz ) ) {
throw new AnnotationException( "Invalid class annotated both '@Entity' and '@Embeddable': '" + clazz.getName() + "'" );
}
else if ( isMappedSuperclass( clazz ) ) {
throw new AnnotationException( "Invalid class annotated both '@Entity' and '@MappedSuperclass': '" + clazz.getName() + "'" );
}
return AnnotatedClassType.ENTITY;
}
else if ( isEmbeddable( clazz ) ) {
if ( isMappedSuperclass( clazz ) ) {
throw new AnnotationException( "Invalid class annotated both '@Embeddable' and '@MappedSuperclass': '" + clazz.getName() + "'" );
}
return AnnotatedClassType.EMBEDDABLE;
}
else if ( isMappedSuperclass( clazz ) ) {
return AnnotatedClassType.MAPPED_SUPERCLASS;
}
else if ( clazz.hasDirectAnnotationUsage( Imported.class ) ) {
return AnnotatedClassType.IMPORTED;
}
else {
return AnnotatedClassType.NONE;
}
}
@Override
public void addMappedSuperclass(Class<?> type, MappedSuperclass mappedSuperclass) {
if ( mappedSuperClasses == null ) {
mappedSuperClasses = new HashMap<>();View on GitHub (pinned to fad1729dce)
Solutions
- Remove either @Embeddable or @MappedSuperclass from the class.
- If the class is a shared base for embeddables, annotate only with @MappedSuperclass; concrete embeddables get @Embeddable.
- Check for accidental annotation duplication through copy-paste in the domain model.
When it happens
Trigger: A class carries a combination of type annotations that are mutually exclusive.
Common situations: Annotating one class with @Entity plus @Embeddable or @MappedSuperclass, or @Embeddable plus @MappedSuperclass, e.g. after refactoring an entity hierarchy.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/af030cd09da921c2.
Report an issue: GitHub.