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

  1. Pass the JPA attribute name (field/property name), not the column name
  2. Validate the name against the metamodel first (managedType.getAttributes()) before probing the graph
  3. Prefer the Attribute-based overload hasAttributeNode(Attribute) when you hold metamodel references
  4. 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

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


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/e2945e7075680f5e. Report an issue: GitHub.