hibernate/hibernate-orm · error · AnnotationException

Invalid class annotated both '@Entity' and '@MappedSuperclas

Error message

Invalid class annotated both '@Entity' and '@MappedSuperclass': '{}'

What it means

Error "Invalid class annotated both '@Entity' and '@MappedSuperclass': '{}'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:1246

	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;
		}
		else {
			return AnnotatedClassType.NONE;
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove either @Entity or @MappedSuperclass from the class.
  2. Use @MappedSuperclass only on abstract base classes that share mapping state, and @Entity on concrete persistable classes.
  3. Review the class hierarchy so each class carries exactly one of the type-defining annotations.

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/acfea58b691825cf. Report an issue: GitHub.