hibernate/hibernate-orm · error · IllegalArgumentException
Unknown attribute: {}
Error message
Unknown attribute: {} What it means
GraphImpl.hasAttributeNode(String) first resolves the name via findAttributeInSupertypes (the graphed type's attributes plus inherited ones) and throws IllegalArgumentException('Unknown attribute: ...') when no such attribute exists — it does not return false for unknown names, unlike the Attribute-based overload. The boolean answer only distinguishes node presence for names that are real attributes.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java:95
@Override
@Nonnull
public List<AttributeNodeImplementor<?,?,?>> getAttributeNodeList() {
return attributeNodes == null ? emptyList() : new ArrayList<>( attributeNodes.values() );
}
@Override
@Nonnull
public Map<PersistentAttribute<? super J, ?>, AttributeNodeImplementor<?,?,?>> getNodes() {
return attributeNodes == null ? emptyMap() : new HashMap<>( attributeNodes );
}
@Override
public boolean hasAttributeNode(@Nonnull String attributeName) {
final var attribute = findAttributeInSupertypes( attributeName );
if ( attribute == null ) {
throw new IllegalArgumentException( "Unknown attribute: " + attributeName );
}
return attributeNodes != null
&& attributeNodes.containsKey( attribute );
}
@Override
public boolean hasAttributeNode(@Nonnull Attribute<? super J, ?> attribute) {
return attributeNodes != null
&& attributeNodes.containsKey( (PersistentAttribute<? super J, ?>) attribute );
}
@Override
@Nonnull
public <Y> AttributeNodeImplementor<Y,?,?> getAttributeNode(@Nonnull String attributeName) {
final var attribute = findAttributeInSupertypes( attributeName );
if ( attribute == null ) {
throw new IllegalArgumentException( "Unknown attribute: " + attributeName );
}View on GitHub (pinned to fad1729dce)
Solutions
- Pass the JPA attribute name (field/property name), not the column name
- Validate the name against the metamodel first (managedType.getAttributes()) before probing the graph
- Prefer the Attribute-based overload hasAttributeNode(Attribute) when you hold metamodel references
- For pure existence probing of arbitrary strings, wrap the call and treat IllegalArgumentException as 'false'
Example fix
// before
boolean has = graph.hasAttributeNode("cust_name"); // column name → IllegalArgumentException
// after
boolean has = graph.hasAttributeNode("customer"); // JPA attribute name Defensive patterns
Strategy: validation
Validate before calling
// Safe existence probe: validate the name against the metamodel, then check node presence
static boolean hasNodeSafely(EntityGraph<?> graph, Metamodel mm, Class<?> type, String attrName) {
try {
mm.managedType(type).getAttribute(attrName); // throws IllegalArgumentException if unknown
}
catch (IllegalArgumentException unknown) {
return false;
}
return graph.getAttributeNodes().stream()
.map(AttributeNode::getAttributeName)
.anyMatch(attrName::equals);
} Prevention
- Use metamodel attribute names, not column names, in graph code
- Prefer the Attribute-based overloads of graph methods
- Validate names against managedType.getAttributes() when building graphs dynamically
When it happens
Trigger: Calling hasAttributeNode(name) with a typo, a database column name instead of the property name, a @Transient field, or an attribute that exists only on a subclass (accessible via treated subgraphs) rather than on the graphed type.
Common situations: Dynamic graph utilities that probe by string; using column names where attribute names are expected; mappings where the attribute lives in a @MappedSuperclass or a different hierarchy level than assumed.
Related errors
- Cannot resolve entity class : {}
- Duplicate named entity graph '%s'
- The 'root' parameter of the @NamedEntityGraph should be pass
- The 'root' parameter of the @NamedEntityGraph annotation mus
- Non-terminal property path did not reference FetchableContai
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e2945e7075680f5e.
Report an issue: GitHub.