hibernate/hibernate-orm · error · AnnotationException
Invalid class annotated both '@Entity' and '@Embeddable': '{
Error message
Invalid class annotated both '@Entity' and '@Embeddable': '{}' What it means
Error "Invalid class annotated both '@Entity' and '@Embeddable': '{}'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:1243
private final Map<String,AnnotatedClassType> annotatedClassTypeMap = new HashMap<>();
@Override
public AnnotatedClassType getClassType(ClassDetails clazz) {
final var type = annotatedClassTypeMap.get( clazz.getName() );
return type == null ? addClassType( clazz ) : type;
}
@Override
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;
}View on GitHub (pinned to fad1729dce)
Solutions
- Remove either @Entity or @Embeddable from the class; a class cannot be both an entity and an embeddable.
- If the class is used as an embedded component, keep only @Embeddable; if it needs its own identity, keep only @Entity.
- Check for conflicting annotations introduced via both the class and a superclass or interface default.
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/355f3bbf0ef8e134.
Report an issue: GitHub.