{"record":{"id":"278012b9f458e6e0","repo":"hibernate/hibernate-orm","slug":"expected-multiple-natural-id-attributes-but-found","errorCode":null,"errorMessage":"Expected multiple natural-id attributes, but found only one: ${entityName}","messagePattern":"Expected multiple natural-id attributes, but found only one: (.+?)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java","lineNumber":5663,"sourceCode":"\t\t// collect the names of the attributes making up the natural-id.\n\t\tfinal Set<String> attributeNames = setOfSize( naturalIdAttributeIndexes.length );\n\t\tfor ( int naturalIdAttributeIndex : naturalIdAttributeIndexes ) {\n\t\t\tattributeNames.add( getPropertyNames()[ naturalIdAttributeIndex ] );\n\t\t}\n\n\t\t// then iterate over the attribute mappings finding the ones having names\n\t\t// in the collected names.  iterate here because it is already alphabetical\n\n\t\tfinal List<SingularAttributeMapping> collectedAttrMappings = new ArrayList<>();\n\t\tfor ( int i = 0; i < attributeMappings.size(); i++ ) {\n\t\t\tfinal var attributeMapping = attributeMappings.get( i );\n\t\t\tif ( attributeNames.contains( attributeMapping.getAttributeName() ) ) {\n\t\t\t\tcollectedAttrMappings.add( (SingularAttributeMapping) attributeMapping );\n\t\t\t}\n\t\t}\n\n\t\tif ( collectedAttrMappings.size() <= 1 ) {\n\t\t\tthrow new MappingException( \"Expected multiple natural-id attributes, but found only one: \" + getEntityName() );\n\t\t}\n\n\t\treturn new CompoundNaturalIdMapping(\n\t\t\t\tthis,\n\t\t\t\tbootEntityDescriptor.getRootClass().getNaturalIdClass(),\n\t\t\t\tcollectedAttrMappings,\n\t\t\t\tcreationProcess\n\t\t);\n\t}\n\n\tprotected static SqmMultiTableMutationStrategy interpretSqmMultiTableStrategy(\n\t\t\tAbstractEntityPersister entityMappingDescriptor,\n\t\t\tMappingModelCreationProcess creationProcess) {\n\t\tassert entityMappingDescriptor.hasMultipleTables();\n\t\tfinal var superMappingType = entityMappingDescriptor.getSuperMappingType();\n\t\tif ( superMappingType != null ) {\n\t\t\tfinal var sqmMultiTableMutationStrategy =\n\t\t\t\t\tsuperMappingType.getSqmMultiTableMutationStrategy();","sourceCodeStart":5645,"sourceCodeEnd":5681,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java#L5645-L5681","documentation":"Error \"Expected multiple natural-id attributes, but found only one: ${entityName}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a compound natural id mapping is expected but the entity declares only one natural-id attribute.","commonSituations":"See trigger scenarios.","solutions":["Annotate all attributes comprising the compound natural id with @NaturalId, or remove @NaturalIdClass if only one attribute forms the natural id."],"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"}