hibernate/hibernate-orm · error · MappingException
Only classes (not interfaces) may be mapped as @Entity : " +
Error message
Only classes (not interfaces) may be mapped as @Entity : " + classDetails.getName()
What it means
Error "Only classes (not interfaces) may be mapped as @Entity : " + classDetails.getName()" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/ManagedTypeProcessor.java:140
);
}
);
DynamicModelHelper.prepareDynamicClass( classDetails, jaxbEntity, xmlDocumentContext );
}
else {
memberAdjuster = ManagedTypeProcessor::adjustCompleteNonDynamicTypeMember;
final String className = XmlProcessingHelper.determineClassName( jaxbRoot, jaxbEntity );
classDetails = (MutableClassDetails) classDetailsRegistry.resolveClassDetails( className );
classAccessType = coalesce(
jaxbEntity.getAccess(),
jaxbRoot.getAccess(),
xmlDocumentContext.getEffectiveDefaults().getDefaultPropertyAccessType(),
defaultAccessTypeFromDefaultAccessor( xmlDocumentContext ),
AccessType.PROPERTY
);
if ( classDetails.isInterface() ) {
throw new MappingException( "Only classes (not interfaces) may be mapped as @Entity : " + classDetails.getName() );
}
classDetails.forEachPersistableMember( memberDetails -> {
final var mutableMemberDetails = (MutableMemberDetails) memberDetails;
mutableMemberDetails.clearAnnotationUsages();
} );
}
classDetails.clearAnnotationUsages();
// In metadata-complete mode the XML is the sole source of truth — annotations have just
// been cleared, so the chosen access type must be stamped on the class regardless of
// whether it came from XML or from a fallback.
applyAccessAnnotation( classAccessType, classDetails, xmlDocumentContext );
// from here, processing is the same between override and metadata-complete modes
// (aside from the dynamic model handling)
View on GitHub (pinned to fad1729dce)
Solutions
- Remove @Entity from the interface; map a concrete class instead, or use the interface only as a target of associations via targetEntity.
Example fix
Remove @Entity from the interface; map a concrete class instead, or use the interface only as a target of associations via targetEntity.
When it happens
Trigger: An hbm.xml / orm.xml mapping document violates a mapping rule during bootstrap.
Common situations: Legacy XML mappings with invalid combinations (column+formula, mixed inheritance, missing identifiers, bad extends references).
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/a9bc9d153a48b072.
Report an issue: GitHub.