hibernate/hibernate-orm · error · MappingException
Discriminator column mapping given for non-discriminated ent
Error message
Discriminator column mapping given for non-discriminated entity [" + entityName + "] as part of resultset mapping [" + registrationName + "]
What it means
An entity <return/> may map a discriminator column alias (classically via <return-property name="class" .../>), which produces a FetchMementoBasic over the discriminator mapping. At resolution time Hibernate fetches the entity descriptor and, when discriminatorColumnAlias is set but entityDescriptor.getDiscriminatorMapping() is null (the entity has no discriminator), throws this MappingException. Only single-table (table-per-class-hierarchy with <discriminator/>) inheritance has a discriminator mapping.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java:392
tableAlias,
entityName,
registrationName
);
final var entityDescriptor =
resolutionContext.getMappingMetamodel()
.getEntityDescriptor( entityName );
applyFetchJoins( joinDescriptorsAccess, tableAlias, propertyFetchDescriptors );
final var entityPath = new NavigablePath( entityName );
final FetchMementoBasic discriminatorMemento;
if ( discriminatorColumnAlias == null ) {
discriminatorMemento = null;
}
else {
if ( entityDescriptor.getDiscriminatorMapping() == null ) {
throw new MappingException(
"Discriminator column mapping given for non-discriminated entity ["
+ entityName + "] as part of resultset mapping [" + registrationName + "]"
);
}
discriminatorMemento = new FetchMementoBasicStandard(
entityPath.append( EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME ),
entityDescriptor.getDiscriminatorMapping(),
discriminatorColumnAlias
);
}
final Map<String, FetchMemento> fetchDescriptorMap = new HashMap<>();
propertyFetchDescriptors.forEach(
hbmFetchDescriptor -> fetchDescriptorMap.put(
hbmFetchDescriptor.getFetchablePath(),
hbmFetchDescriptor.resolve( resolutionContext )
)View on GitHub (pinned to fad1729dce)
Solutions
- Remove the <return-property name="class" .../> entry if the entity is not discriminator-polymorphic.
- Or switch the entity to single-table inheritance with an explicit <discriminator column="..."/> so the mapping is valid.
- Double-check the entity name in the <return/> is the polymorphic root you intended.
Example fix
<!-- before: Order has joined-subclass inheritance, no discriminator -->
<return alias="o" entity-name="com.acme.Order">
<return-property name="class" column="ORDER_TYPE"/>
</return>
<!-- after: drop the discriminator mapping -->
<return alias="o" entity-name="com.acme.Order"/> Defensive patterns
Strategy: validation
Validate before calling
// before bootstrapping, if a <return-property name="class"> exists, confirm the entity is single-table:
boolean singleTable = entityElement.element( "discriminator" ) != null; // for hbm mappings
if ( !singleTable && hasClassReturnProperty ) {
throw new IllegalStateException( "Discriminator return-property requires a discriminated entity" );
} Try / catch
catch ( MappingException e ) {
if ( e.getMessage().startsWith( "Discriminator column mapping given for non-discriminated entity" ) ) {
// remove the 'class' return-property or switch the entity to single-table inheritance
}
} Prevention
- Only map a discriminator column alias for single-table inheritance roots.
- When changing inheritance strategy, review all native query mappings that touch the hierarchy.
When it happens
Trigger: <return-property name="class" column="TYPE"/> inside a <return> whose entity uses joined or union-subclass inheritance, or has no inheritance at all; copying a polymorphic query mapping onto a non-polymorphic entity.
Common situations: Inheritance strategy switched from single-table to joined while the native query mapping kept the 'class' return-property; query mappings reused across entities via templates.
Related errors
- Root entity '<entityName>' is annotated '@DiscriminatorOptio
- Class '<className>' is not the root class of an entity inher
- Cannot combine other returns with a collection return (" + r
- Illegal <return-join/> property attribute: '" + fullProperty
- Property join specified twice for join-return '" + ownerTabl
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e03da410fb530af6.
Report an issue: GitHub.