{"record":{"id":"fe4e4b8263e0422d","repo":"hibernate/hibernate-orm","slug":"incoming-natural-id-value-s-s-is-not-of-ex","errorCode":null,"errorMessage":"Incoming natural-id value [%s (`%s`)] is not of expected type [`%s`] and could not be coerced","messagePattern":"Incoming natural-id value \\[(.+?) \\(`(.+?)`\\)\\] is not of expected type \\[`(.+?)`\\] and could not be coerced","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java","lineNumber":125,"sourceCode":"\t@Override\n\tpublic boolean isNormalized(Object incoming) {\n\t\treturn incoming == null || getJavaType().getJavaTypeClass().isInstance( incoming );\n\t}\n\n\t@Override\n\tpublic void validateInternalForm(Object naturalIdValue) {\n\t\tif ( naturalIdValue != null ) {\n\t\t\tfinal var naturalIdValueClass = naturalIdValue.getClass();\n\t\t\t// be flexible - allow a single-valued array\n\t\t\tif ( naturalIdValueClass.isArray() && !naturalIdValueClass.getComponentType().isPrimitive() ) {\n\t\t\t\tfinal var values = (Object[]) naturalIdValue;\n\t\t\t\tif ( values.length == 1 ) {\n\t\t\t\t\tnaturalIdValue = values[0];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( !getJavaType().isInstance( naturalIdValue ) ) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\t\"Incoming natural-id value [%s (`%s`)] is not of expected type [`%s`] and could not be coerced\",\n\t\t\t\t\t\t\t\tnaturalIdValue,\n\t\t\t\t\t\t\t\tnaturalIdValueClass.getName(),\n\t\t\t\t\t\t\t\tgetJavaType().getTypeName()\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic int calculateHashCode(Object value) {\n\t\t//noinspection rawtypes,unchecked\n\t\treturn value == null ? 0 : ( (JavaType) getJavaType() ).extractHashCode( value );\n\t}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/SimpleNaturalIdMapping.java#L107-L143","documentation":"Error \"Incoming natural-id value [%s (`%s`)] is not of expected type [`%s`] and could not be coerced\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a natural-id value supplied for loading has a Java type that does not match the declared attribute type and cannot be coerced.","commonSituations":"See trigger scenarios.","solutions":["Pass a natural-id value of the exact Java type of the natural-id attribute.","Ensure the value can be coerced (e.g. correct numeric/string form) to the natural-id attribute type."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}