{"record":{"id":"83a3d10fb7c36adb","repo":"hibernate/hibernate-orm","slug":"could-not-locate-field-for-property-named-con","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/PropertyAccessEnhancedImpl.java","lineNumber":57,"sourceCode":"\tprivate final Setter setter;\n\n\tpublic PropertyAccessEnhancedImpl(\n\t\t\tPropertyAccessStrategy strategy,\n\t\t\tClass<?> containerJavaType,\n\t\t\tString propertyName,\n\t\t\t@Nullable AccessType classAccessType) {\n\t\tthis.strategy = strategy;\n\n\t\tfinal var propertyAccessType =\n\t\t\t\tclassAccessType == null\n\t\t\t\t\t\t? getAccessType( containerJavaType, propertyName )\n\t\t\t\t\t\t: classAccessType;\n\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 = new GetterFieldImpl( containerJavaType, propertyName, field );\n\t\t\t\tsetter = new EnhancedSetterImpl( 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( classAccessType, containerJavaType, propertyName, getterMethod );\n\t\t\t\tsetter = propertySetter( classAccessType, containerJavaType, propertyName, getterMethod.getReturnType() );\n\t\t\t\tbreak;\n\t\t\t}","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java#L39-L75","documentation":"PropertyAccessEnhancedImpl builds access for bytecode-enhanced entities: it resolves the access type (explicit class-level or inferred) and, for FIELD access, looks up the Field reflectively via fieldOrNull. A null result throws PropertyAccessBuildingException 'Could not locate field for property named [Class#property]' — the mapping references a property name that has no backing field on the class.","triggerScenarios":"A mapping (XML <property name=\"...\"> or annotation metadata) naming a property that is not a declared field, while the resolved access type is FIELD — typos, stale mapping files after a field rename, or metadata written for a different class version.","commonSituations":"Renaming a Java field without updating orm.xml or annotation metadata; @Access(AccessType.FIELD) on a class where the value only exists as a getter; Kotlin/Scala classes where the mapped name differs from the backing field; stale bytecode-enhanced classes after a refactor.","solutions":["Fix the mapped property name so it matches a declared field on containerJavaType exactly","If the value lives on a getter, annotate that member with @Access(AccessType.PROPERTY) so PROPERTY access is resolved","Re-run the bytecode-enhancement build task after renames so enhanced classes and mapping metadata agree","Add a bootstrap test that builds the SessionFactory so bad property names fail at build time, not at runtime"],"exampleFix":"// before\n@Access(AccessType.FIELD)\npublic class Order {\n    @Column(name = \"order_date\")\n    private LocalDate orderDat; // mapping/metadata says orderDate\n}\n\n// after\npublic class Order {\n    @Column(name = \"order_date\")\n    private LocalDate orderDate;\n}","handlingStrategy":"validation","validationCode":"// Fail fast at startup: every mapped property must exist as a field\nfor (String prop : new String[]{\"orderDate\", \"amount\", \"status\"}) {\n    try {\n        Order.class.getDeclaredField(prop);\n    } catch (NoSuchFieldException e) {\n        throw new IllegalStateException(\"Mapping references missing field: Order#\" + prop, e);\n    }\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 backing field: fix the mapping or add @Access(PROPERTY)\n}","preventionTips":["Keep mapping metadata and field names in sync during renames","Build the SessionFactory in a CI test so mapping drift fails at build time","Use @Access explicitly when a property is only a getter or only a field","Re-run bytecode enhancement after entity refactors"],"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"}