{"record":{"id":"df8f617f29fe2ca3","repo":"hibernate/hibernate-orm","slug":"naturalidclass-not-supported-for-simple-naturaal-i","errorCode":null,"errorMessage":"NaturalIdClass not supported for simple naturaal-id mappings","messagePattern":"NaturalIdClass not supported for simple naturaal-id mappings","errorType":"exception","errorClass":"UnsupportedMappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java","lineNumber":5634,"sourceCode":"\t\t\tnaturalIdMapping = generateNaturalIdMapping( creationProcess, bootEntityDescriptor );\n\t\t}\n\t\telse {\n\t\t\tnaturalIdMapping = null;\n\t\t}\n\t}\n\n\tprotected NaturalIdMapping generateNaturalIdMapping(\n\t\t\tMappingModelCreationProcess creationProcess,\n\t\t\tPersistentClass bootEntityDescriptor) {\n\t\t//noinspection AssertWithSideEffects\n\t\tassert bootEntityDescriptor.hasNaturalId();\n\n\t\tfinal int[] naturalIdAttributeIndexes = getNaturalIdentifierProperties();\n\t\tassert naturalIdAttributeIndexes.length > 0;\n\n\t\tif ( naturalIdAttributeIndexes.length == 1 ) {\n\t\t\tif ( bootEntityDescriptor.getRootClass().getNaturalIdClass() != null ) {\n\t\t\t\tthrow new UnsupportedMappingException( \"NaturalIdClass not supported for simple naturaal-id mappings\" );\n\t\t\t}\n\t\t\tfinal String propertyName = getPropertyNames()[ naturalIdAttributeIndexes[ 0 ] ];\n\t\t\tfinal var attributeMapping = (SingularAttributeMapping) findAttributeMapping( propertyName );\n\t\t\treturn new SimpleNaturalIdMapping(\n\t\t\t\t\tattributeMapping,\n\t\t\t\t\tthis,\n\t\t\t\t\tcreationProcess\n\t\t\t);\n\t\t}\n\n\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","sourceCodeStart":5616,"sourceCodeEnd":5652,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java#L5616-L5652","documentation":"Error \"NaturalIdClass not supported for simple naturaal-id mappings\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a NaturalIdClass is declared for an entity that has only a single (simple) natural-id attribute.","commonSituations":"See trigger scenarios.","solutions":["Remove @NaturalIdClass usage for a single-attribute natural id; annotate the attribute with @NaturalId directly.","Add a second natural-id attribute if a compound NaturalIdClass is intended."],"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"}