{"record":{"id":"0707bf0352a7c07c","repo":"hibernate/hibernate-orm","slug":"unable-to-find-naturalidclass-accessor-for-natural","errorCode":null,"errorMessage":"Unable to find NaturalIdClass accessor for natural id attribute: %s","messagePattern":"Unable to find NaturalIdClass accessor for natural id attribute: (.+?)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java","lineNumber":854,"sourceCode":"\t\t\t\treturn new GetterMethodImpl( naturalIdClass, keyName, component.getAccessor() );\n\t\t\t}\n\t\t}\n\n\t\t// next look for a getter method\n\t\tfinal var getterMethod = getterMethodAccess.apply( keyName );\n\t\tif ( getterMethod != null ) {\n\t\t\treturn new GetterMethodImpl( naturalIdClass, keyName, getterMethod );\n\t\t}\n\n\t\t// lastly, look for a field\n\t\ttry {\n\t\t\treturn new GetterFieldImpl( naturalIdClass, keyName,\n\t\t\t\t\tnaturalIdClass.getDeclaredField( keyName ) );\n\t\t}\n\t\tcatch (NoSuchFieldException ignore) {\n\t\t}\n\n\t\tthrow new MappingException( \"Unable to find NaturalIdClass accessor for natural id attribute: \" + keyName );\n\t}\n\n\tprivate static <T> Map<String, Method> extractGetterMethods(Class<T> naturalIdClass) {\n\t\tfinal Map<String, Method> result = new HashMap<>();\n\t\tfor ( var declaredMethod : naturalIdClass.getDeclaredMethods() ) {\n\t\t\tif ( declaredMethod.getParameterCount() == 0\n\t\t\t\t&& declaredMethod.getReturnType() != void.class\n\t\t\t\t&& !isStatic( declaredMethod.getModifiers() ) ) {\n\t\t\t\tvar methodName = declaredMethod.getName();\n\t\t\t\tif ( methodName.startsWith( \"is\" ) ) {\n\t\t\t\t\tresult.put( decapitalize( methodName.substring( 2 ) ),\n\t\t\t\t\t\t\tdeclaredMethod );\n\t\t\t\t}\n\t\t\t\telse if ( methodName.startsWith( \"get\" ) ) {\n\t\t\t\t\tresult.put( decapitalize( methodName.substring( 3 ) ),\n\t\t\t\t\t\t\tdeclaredMethod );\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java#L836-L872","documentation":"Error \"Unable to find NaturalIdClass accessor for natural id attribute: %s\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a compound natural id uses a NaturalIdClass but no accessor can be found for one of its attributes.","commonSituations":"See trigger scenarios.","solutions":["Ensure the NaturalIdClass has a readable property for every natural-id attribute of the entity.","Check that the NaturalIdClass attribute names match the entity's natural-id attribute names."],"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"}