hibernate/hibernate-orm · error · MappingException
Unable to interpret <meta-value value="%s" class="%s"/> defi
Error message
Unable to interpret <meta-value value="%s" class="%s"/> defined as part of <any/> attribute [%s]
What it means
Inside an <any> mapping, each <meta-value value='...' class='...'/> entry maps a discriminator literal to an entity name. Hibernate converts each value string to the discriminator type's Java representation via its JavaTypeDescriptor.fromString(). Any exception thrown during that conversion (unparseable literal, wrong type, null) is wrapped in this MappingException together with the original cause.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java:2085
}
}
private static Map<DiscriminatorValue, String> discriminatorValueToEntityNameMap(
MappingDocument sourceDocument,
AnyMappingSource anyMapping,
AttributeRole attributeRole,
BasicType<?> discriminatorType) {
final Map<DiscriminatorValue, String> discriminatorValueToEntityNameMap = new HashMap<>();
anyMapping.getDiscriminatorSource().getValueMappings().forEach(
(discriminatorValueString, entityName) -> {
try {
final Object discriminatorValue =
discriminatorType.getJavaTypeDescriptor()
.fromString( discriminatorValueString );
discriminatorValueToEntityNameMap.put( new DiscriminatorValue.Literal( discriminatorValue ), entityName );
}
catch (Exception exception) {
throw new MappingException(
"Unable to interpret <meta-value value=\"%s\" class=\"%s\"/> defined as part of <any/> attribute [%s]"
.formatted( discriminatorValueString, entityName, attributeRole.getFullPath() ),
exception,
sourceDocument.getOrigin()
);
}
}
);
return discriminatorValueToEntityNameMap;
}
private BasicType<?> resolveExplicitlyNamedAnyDiscriminatorType(
String typeName,
Map<String, String> parameters,
Any.MetaValue discriminatorMapping) {
final var bootstrapContext = metadataBuildingContext.getBootstrapContext();
final var typeConfiguration = bootstrapContext.getTypeConfiguration();
View on GitHub (pinned to fad1729dce)
Solutions
- Make every <meta-value> value literal parseable by the declared meta-type (e.g. '1', '2' for an Integer meta-type)
- Fix or remove the specific <meta-value> entry named in the message (value and class are printed)
- If a custom meta-type is used, ensure its JavaTypeDescriptor.fromString implementation accepts all declared literals
Example fix
// before
<any name='payload' meta-type='integer' id-type='long'>
<column name='payload_type'/>
<column name='payload_id'/>
<meta-value value='ONE' class='TextPayload'/>
</any>
// after
<any name='payload' meta-type='integer' id-type='long'>
<column name='payload_type'/>
<column name='payload_id'/>
<meta-value value='1' class='TextPayload'/>
</any> Defensive patterns
Strategy: validation
Validate before calling
// fail fast: try parsing each meta-value literal with the declared meta-type before Hibernate does
BasicType<?> metaType = typeConfiguration.getBasicTypeForJavaType(Integer.class);
NodeList mvs = doc.getElementsByTagName("meta-value");
for (int i = 0; i < mvs.getLength(); i++) {
String literal = ((Element) mvs.item(i)).getAttribute("value");
try {
metaType.getJavaTypeDescriptor().fromString(literal);
} catch (Exception ex) {
throw new IllegalStateException("meta-value '" + literal + "' does not parse as " + metaType.getJavaTypeDescriptor().getJavaType(), ex);
}
} Try / catch
catch (MappingException e) at bootstrap and inspect getCause() - it holds the original conversion exception (e.g. NumberFormatException). Fix the printed value/class pair to match the declared meta-type.
Prevention
- Keep meta-value literals in sync with the declared meta-type
- Prefer @Any / @JdbcTypeCode with an enum or a well-known literal format over hand-written meta-values
- Test mappings in a unit test that builds a Metadata instance before deploying
When it happens
Trigger: An <any> with an Integer meta-type but a meta-value like value='ONE'; meta-value literals that do not match the declared meta-type; empty or malformed value strings; a custom meta-type whose JavaTypeDescriptor.fromString rejects the literal.
Common situations: Switching the meta-type (e.g. String to Integer) without updating the meta-value literals; typos in numeric literals; introducing a custom discriminator type and forgetting its accepted literal format.
Related errors
- Entity discriminator cannot be de-referenced
- Root entity '<entityName>' is annotated '@DiscriminatorOptio
- Class '<className>' is not the root class of an entity inher
- Class '<componentClassName>' is an '@Embeddable' type and ma
- transformation of <any/> as part of <join/> (secondary-table
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/dd46d114c4eb1860.
Report an issue: GitHub.