{"record":{"id":"1b6ddc28dd89bcbd","repo":"hibernate/hibernate-orm","slug":"could-not-locate-field-for-property-named-con-1b6ddc","errorCode":null,"errorMessage":"Could not locate field for property named [\" + containerJavaType.getName() + \"#\" + propertyName + \"]","messagePattern":"Could not locate field for property named \\[\" \\+ containerJavaType\\.getName\\(\\) \\+ \"#\" \\+ propertyName \\+ \"\\]","errorType":"exception","errorClass":"PropertyAccessBuildingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java","lineNumber":41,"sourceCode":"/**\n * A {@link PropertyAccess} based on mix of getter method or field.\n *\n * @author Gavin King\n */\npublic class PropertyAccessGetterImpl implements PropertyAccess {\n\tprivate final PropertyAccessStrategy strategy;\n\n\tprivate final Getter getter;\n\n\tpublic PropertyAccessGetterImpl(PropertyAccessStrategy strategy, Class<?> containerJavaType, String propertyName) {\n\t\tthis.strategy = strategy;\n\n\t\tfinal var propertyAccessType = getAccessType( containerJavaType, propertyName );\n\t\tswitch ( propertyAccessType ) {\n\t\t\tcase FIELD: {\n\t\t\t\tfinal var field = fieldOrNull( containerJavaType, propertyName );\n\t\t\t\tif ( field == null ) {\n\t\t\t\t\tthrow new PropertyAccessBuildingException(\n\t\t\t\t\t\t\t\"Could not locate field for property named [\" + containerJavaType.getName() + \"#\" + propertyName + \"]\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tgetter = fieldGetter( containerJavaType, propertyName, field );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase PROPERTY: {\n\t\t\t\tfinal var getterMethod = getterMethodOrNull( containerJavaType, propertyName );\n\t\t\t\tif ( getterMethod == null ) {\n\t\t\t\t\tthrow new PropertyAccessBuildingException(\n\t\t\t\t\t\t\t\"Could not locate getter for property named [\" + containerJavaType.getName() + \"#\" + propertyName + \"]\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tgetter = propertyGetter( containerJavaType, propertyName, getterMethod );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new PropertyAccessBuildingException(","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessGetterImpl.java#L23-L59","documentation":"PropertyAccessGetterImpl builds getter-only access strategies (used where only reads are needed). It resolves the access type, and for FIELD access looks the Field up via fieldOrNull; a null result throws PropertyAccessBuildingException 'Could not locate field for property named [Class#property]' at mapping time — the property name has no backing field.","triggerScenarios":"A getter-only strategy resolved for a mapped property whose name matches no declared field on containerJavaType — for example @EmbeddedId / virtual-id mappings after a field rename, an orm.xml typo, or computed getters where FIELD access was resolved from class-level @Access.","commonSituations":"Identifier and embedded-id mappings drifting from class changes; orm.xml property-name typos; refactors that renamed the field but left metadata behind; property names that only exist as getter methods with field access inferred.","solutions":["Make the mapped property name match a declared field exactly","If the value exists only as a getter, force PROPERTY access with @Access(AccessType.PROPERTY) on that member","Re-run enhancement and rebuild metadata after field renames","Bootstrap the SessionFactory in a test to surface mapping/property drift early"],"exampleFix":"// before\n<attributes>\n    <id name=\"identifer\" .../> <!-- field is named identifier -->\n</attributes>\n\n// after\n<attributes>\n    <id name=\"identifier\" .../>\n</attributes>","handlingStrategy":"validation","validationCode":"// Fail fast: every getter-only mapped property must have a backing field\ntry {\n    OrderId.class.getDeclaredField(\"number\");\n} catch (NoSuchFieldException e) {\n    throw new IllegalStateException(\"Mapping references missing field: OrderId#number\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    SessionFactory sf = metadata.buildSessionFactory();\n} catch (org.hibernate.property.access.internal.PropertyAccessBuildingException e) {\n    // mapping names a property with no field: fix the name or use @Access(PROPERTY)\n}","preventionTips":["Keep embedded-id and orm.xml property names synchronized with field names","Add @Access(PROPERTY) for computed getter-only values","Include a SessionFactory bootstrap test in the build"],"tags":["hibernate","mapping","property-access","reflection","bootstrap"],"backgroundTag":"missing-property-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}