{"record":{"id":"dd46d114c4eb1860","repo":"hibernate/hibernate-orm","slug":"unable-to-interpret-meta-value-value-s-class","errorCode":null,"errorMessage":"Unable to interpret <meta-value value=\"%s\" class=\"%s\"/> defined as part of <any/> attribute [%s]","messagePattern":"Unable to interpret <meta-value value=\"(.+?)\" class=\"(.+?)\"/> defined as part of <any/> attribute \\[(.+?)\\]","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java","lineNumber":2085,"sourceCode":"\t\t}\n\t}\n\n\tprivate static Map<DiscriminatorValue, String> discriminatorValueToEntityNameMap(\n\t\t\tMappingDocument sourceDocument,\n\t\t\tAnyMappingSource anyMapping,\n\t\t\tAttributeRole attributeRole,\n\t\t\tBasicType<?> discriminatorType) {\n\t\tfinal Map<DiscriminatorValue, String> discriminatorValueToEntityNameMap = new HashMap<>();\n\t\tanyMapping.getDiscriminatorSource().getValueMappings().forEach(\n\t\t\t\t(discriminatorValueString, entityName) -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tfinal Object discriminatorValue =\n\t\t\t\t\t\t\t\tdiscriminatorType.getJavaTypeDescriptor()\n\t\t\t\t\t\t\t\t\t\t.fromString( discriminatorValueString );\n\t\t\t\t\t\tdiscriminatorValueToEntityNameMap.put( new DiscriminatorValue.Literal( discriminatorValue ), entityName );\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Exception exception) {\n\t\t\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\t\t\t\"Unable to interpret <meta-value value=\\\"%s\\\" class=\\\"%s\\\"/> defined as part of <any/> attribute [%s]\"\n\t\t\t\t\t\t\t\t\t\t.formatted( discriminatorValueString, entityName, attributeRole.getFullPath() ),\n\t\t\t\t\t\t\t\texception,\n\t\t\t\t\t\t\t\tsourceDocument.getOrigin()\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t);\n\t\treturn discriminatorValueToEntityNameMap;\n\t}\n\n\tprivate BasicType<?> resolveExplicitlyNamedAnyDiscriminatorType(\n\t\t\tString typeName,\n\t\t\tMap<String, String> parameters,\n\t\t\tAny.MetaValue discriminatorMapping) {\n\t\tfinal var bootstrapContext = metadataBuildingContext.getBootstrapContext();\n\t\tfinal var typeConfiguration = bootstrapContext.getTypeConfiguration();\n","sourceCodeStart":2067,"sourceCodeEnd":2103,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L2067-L2103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n<any name='payload' meta-type='integer' id-type='long'>\n    <column name='payload_type'/>\n    <column name='payload_id'/>\n    <meta-value value='ONE' class='TextPayload'/>\n</any>\n\n// after\n<any name='payload' meta-type='integer' id-type='long'>\n    <column name='payload_type'/>\n    <column name='payload_id'/>\n    <meta-value value='1' class='TextPayload'/>\n</any>","handlingStrategy":"validation","validationCode":"// fail fast: try parsing each meta-value literal with the declared meta-type before Hibernate does\nBasicType<?> metaType = typeConfiguration.getBasicTypeForJavaType(Integer.class);\nNodeList mvs = doc.getElementsByTagName(\"meta-value\");\nfor (int i = 0; i < mvs.getLength(); i++) {\n    String literal = ((Element) mvs.item(i)).getAttribute(\"value\");\n    try {\n        metaType.getJavaTypeDescriptor().fromString(literal);\n    } catch (Exception ex) {\n        throw new IllegalStateException(\"meta-value '\" + literal + \"' does not parse as \" + metaType.getJavaTypeDescriptor().getJavaType(), ex);\n    }\n}","typeGuard":null,"tryCatchPattern":"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.","preventionTips":["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"],"tags":["hibernate","hbm-mapping","any-mapping","meta-value","discriminator"],"backgroundTag":"any-mapping-meta-value-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}