{"record":{"id":"2d2299a8d357f87a","repo":"hibernate/hibernate-orm","slug":"unable-to-locate-s-with-the-given-name-s-on-th","errorCode":null,"errorMessage":"Unable to locate %s with the given name [%s] on this ManagedType [%s]","messagePattern":"Unable to locate (.+?) with the given name \\[(.+?)\\] on this ManagedType \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java","lineNumber":247,"sourceCode":"\t\telse if ( declaredPluralAttributes != null ) {\n\t\t\treturn declaredPluralAttributes.get( name );\n\t\t}\n\t\telse {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic PersistentAttribute<J,?> getDeclaredAttribute(@Nonnull String name) {\n\t\tfinal var attribute = findDeclaredAttribute( name );\n\t\tcheckNotNull( \"Attribute\", attribute, name );\n\t\treturn attribute;\n\t}\n\n\tprivate void checkNotNull(String attributeType, Attribute<?,?> attribute, String name) {\n\t\tif ( attribute == null ) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\"Unable to locate %s with the given name [%s] on this ManagedType [%s]\",\n\t\t\t\t\t\t\tattributeType,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tgetTypeName()\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override\n\tpublic String getTypeName() {\n\t\treturn hibernateTypeName;\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Singular attributes","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java#L229-L265","documentation":"A metamodel lookup by name failed: getDeclaredAttribute(name) (and the collection get* methods via checkNotNull) found no declared attribute with that exact name on this ManagedType. IllegalArgumentException names the requested attribute type, the name, and the type. Names are Java property names, not column names, and the declared variant does not see inherited attributes.","triggerScenarios":"managedType.getDeclaredAttribute(\"email\") when the field is 'eMail' or inherited from a superclass; using the DB column name (\"EMAIL\" or \"email_address\") instead of the property name; typos in Criteria/JPQL metamodel usage; calling the declared variant for inherited fields.","commonSituations":"Renaming a field without updating all metamodel/string lookups. Mixing column naming strategies (camelCase vs snake_case) — attributes use the Java name. Code generation with wrong casing. Inherited attributes (declared variant misses them).","solutions":["Use the exact Java property name and the non-declared getAttribute(name) to also find inherited attributes","List valid names when debugging: managedType.getAttributes().forEach(a -> System.out.println(a.getName()))","Prefer the canonical JPA metamodel class (StaticMetamodel) or the SingularAttribute references to get compile-time safety instead of strings"],"exampleFix":"// before\nAttribute<Person,?> a = personType.getDeclaredAttribute(\"EMAIL\"); // column name -> throws\n\n// after\nAttribute<Person,?> a = personType.getAttribute(\"email\"); // Java property name, inherited ok","handlingStrategy":"type-guard","validationCode":"// Validate the name before the typed getter\nString name = /* input */;\nboolean exists = StreamSupport.stream(managedType.getAttributes().spliterator(), false)\n        .anyMatch(a -> a.getName().equals(name));\nif (!exists) throw new IllegalArgumentException(\"Unknown attribute '\" + name + \"' on \" + managedType.getTypeName());","typeGuard":"static java.util.Optional<Attribute<?,?>> findAttr(ManagedType<?> type, String name) {\n    for (Attribute<?,?> a : type.getAttributes()) {\n        if (a.getName().equals(name)) return java.util.Optional.of(a);\n    }\n    return java.util.Optional.empty(); // also searches supertype via getAttributes()\n}","tryCatchPattern":"try {\n    return managedType.getDeclaredAttribute(name);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Unable to locate\")) {\n        throw new NoSuchFieldException(\"No attribute '\" + name + \"' on \" + managedType.getTypeName());\n    }\n    throw e;\n}","preventionTips":["Use Java property names, never column names, for metamodel lookups","Prefer the generated static metamodel (@StaticMetamodel) for compile-time safety","Use getAttribute(name) (hierarchy-aware) instead of getDeclaredAttribute(name) unless declared-only is intended","Fail with the list of valid attribute names in your own error messages"],"tags":["hibernate","jpa-metamodel","attribute-lookup","name-mismatch","illegal-argument"],"backgroundTag":"jpa-metamodel-attribute-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}