{"record":{"id":"33028bc9a8f2b98d","repo":"hibernate/hibernate-orm","slug":"natural-id-value-naturalidvalue-did-not-contai","errorCode":null,"errorMessage":"Natural-id value [{naturalIdValue}] did not contain the expected number of elements [{attributes.size()}]","messagePattern":"Natural-id value \\[(.+?)\\] did not contain the expected number of elements \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java","lineNumber":179,"sourceCode":"\t\t\treturn array;\n\t\t}\n\t\telse {\n\t\t\treturn valueNormalizer.normalize( incoming );\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean isNormalized(Object incoming) {\n\t\treturn incoming instanceof Object[];\n\t}\n\n\t@Override\n\tpublic void validateInternalForm(Object naturalIdValue) {\n\t\tif ( naturalIdValue != null ) {\n\t\t\t// should be an array, with a size equal to the number of attributes making up this compound natural-id\n\t\t\tif ( naturalIdValue instanceof Object[] values ) {\n\t\t\t\tif ( values.length != attributes.size() ) {\n\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\"Natural-id value [\" + naturalIdValue + \"] did not contain the expected number of elements [\"\n\t\t\t\t\t\t\t+ attributes.size() + \"]\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Natural-id value [\" + naturalIdValue + \"] was not an array as expected\" );\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic int calculateHashCode(Object value) {\n\t\tif ( value == null ) {\n\t\t\treturn 0;\n\t\t}\n\t\telse {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java#L161-L197","documentation":"Error \"Natural-id value [{naturalIdValue}] did not contain the expected number of elements [{attributes.size()}]\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a compound natural-id value array has fewer or more elements than the entity's declared natural-id attributes.","commonSituations":"See trigger scenarios.","solutions":["Pass a natural-id value array whose size equals the number of attributes of the compound natural id.","Use the natural-id access API (Session.byNaturalId with using()) instead of hand-built arrays."],"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"}