hibernate/hibernate-orm · error · IllegalArgumentException

Attribute '{}' is not of type '{}'

Error message

Attribute '{}' is not of type '{}'

What it means

Error "Attribute '{}' is not of type '{}'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/restriction/NamedPathElement.java:28

/**
 * A non-root element of a {@link Path}, using a stringly-typed
 * attribute reference.
 *
 * @author Gavin King
 */
record NamedPathElement<X, U, V>(Path<? super X, U> parent, String attributeName, Class<V> attributeType)
		implements Path<X, V> {
	@Override
	public Class<V> getType() {
		return attributeType;
	}

	@Override
	public jakarta.persistence.criteria.Path<V> path(Root<? extends X> root) {
		final jakarta.persistence.criteria.Path<V> path = parent.path( root ).get( attributeName );
		if ( !attributeType.isAssignableFrom( path.getJavaType() ) ) {
			throw new IllegalArgumentException( "Attribute '" + attributeName
												+ "' is not of type '" + attributeType.getName() + "'" );
		}
		return path;
	}

	@Override
	public FetchParent<?, V> fetch(Root<? extends X> root) {
		return parent.fetch( root ).fetch( attributeName, JoinType.LEFT );
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. The attribute is not of the required type. Check the attribute name and the expected type in the restriction.

When it happens

Trigger: A range/restriction references an attribute of the wrong kind or type: Attribute '<value>' is not of type '<value>'

Common situations: Defining NamedAttributeRange/NamedPathElement over plural attributes or attributes of a mismatched type.


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