hibernate/hibernate-orm · error · IllegalArgumentException
Unable to locate %s with the given name [%s] on this Managed
Error message
Unable to locate %s with the given name [%s] on this ManagedType [%s]
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java:247
else if ( declaredPluralAttributes != null ) {
return declaredPluralAttributes.get( name );
}
else {
return null;
}
}
@Override
@Nonnull
public PersistentAttribute<J,?> getDeclaredAttribute(@Nonnull String name) {
final var attribute = findDeclaredAttribute( name );
checkNotNull( "Attribute", attribute, name );
return attribute;
}
private void checkNotNull(String attributeType, Attribute<?,?> attribute, String name) {
if ( attribute == null ) {
throw new IllegalArgumentException(
String.format(
"Unable to locate %s with the given name [%s] on this ManagedType [%s]",
attributeType,
name,
getTypeName()
)
);
}
}
@Override
public String getTypeName() {
return hibernateTypeName;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Singular attributesView on GitHub (pinned to fad1729dce)
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
Example fix
// before
Attribute<Person,?> a = personType.getDeclaredAttribute("EMAIL"); // column name -> throws
// after
Attribute<Person,?> a = personType.getAttribute("email"); // Java property name, inherited ok Defensive patterns
Strategy: type-guard
Validate before calling
// Validate the name before the typed getter
String name = /* input */;
boolean exists = StreamSupport.stream(managedType.getAttributes().spliterator(), false)
.anyMatch(a -> a.getName().equals(name));
if (!exists) throw new IllegalArgumentException("Unknown attribute '" + name + "' on " + managedType.getTypeName()); Type guard
static java.util.Optional<Attribute<?,?>> findAttr(ManagedType<?> type, String name) {
for (Attribute<?,?> a : type.getAttributes()) {
if (a.getName().equals(name)) return java.util.Optional.of(a);
}
return java.util.Optional.empty(); // also searches supertype via getAttributes()
} Try / catch
try {
return managedType.getDeclaredAttribute(name);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Unable to locate")) {
throw new NoSuchFieldException("No attribute '" + name + "' on " + managedType.getTypeName());
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Illegal call to IdentifiableType#getId for class [{}] define
- This class [{}] does not define an IdClass
- The version attribute is not declared or inherited by this t
- No singular attribute named '{}' and of type '{}' in type '{
- Not a treatable type: {}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/2d2299a8d357f87a.
Report an issue: GitHub.