hibernate/hibernate-orm · error · IllegalArgumentException

Attribute '{}' is not assignable to range of type '{}'

Error message

Attribute '{}' is not assignable to range of type '{}'

What it means

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

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/restriction/NamedAttributeRange.java:42

record NamedAttributeRange<X, U>(Class<X> entity, String attributeName, Range<U> range) implements Restriction<X> {
	@Override
	public Restriction<X> negated() {
		return new Negation<>( this );
	}

	@Override
	public Predicate toPredicate(Root<? extends X> root, CriteriaBuilder builder) {
		final EntityType<? extends X> entityType = root.getModel();
		if ( !entity.isAssignableFrom( entityType.getJavaType() ) ) {
			throw new IllegalArgumentException( "Root entity is not a subtype of '" + entity.getTypeName() + "'" );
		}
		final Attribute<?, ?> attribute = entityType.getAttribute( attributeName );
		if ( !(attribute instanceof SingularAttribute) ) {
			throw new IllegalArgumentException( "Attribute '" + attributeName + "' is not singular" );
		}
		final Class<? extends U> rangeType = range.getType();
		if ( rangeType != null && !rangeType.isAssignableFrom( attribute.getJavaType() ) ) {
			throw new IllegalArgumentException( "Attribute '" + attributeName
												+ "' is not assignable to range of type '" + rangeType.getName() + "'" );
		}
		return range.toPredicate( root.get( attributeName ), builder );
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. The attribute type is not assignable to the range type. Use an attribute whose type matches the range bounds.

When it happens

Trigger: A parameter is bound with a value or type incompatible with its declared type: Attribute '<value>' is not assignable to range of type '<value>'

Common situations: Binding a Java value whose type does not match the parameter's declared Hibernate/Java type, or passing a mismatched Class/TypedParameterValue to setParameter().


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