hibernate/hibernate-orm · error · FunctionArgumentException

Function %s() has parameters of type %s, but argument of typ

Error message

Function %s() has parameters of type %s, but argument of type %s given

What it means

StandardArgumentsValidators.of(javaType) builds a validator that requires every argument of an HQL function call to be assignable to one Java class. During query parsing it inspects each SqmTypedNode's Java type (getNodeJavaType().getJavaTypeClass()) and throws FunctionArgumentException on the first argument not assignable to it. It is the type-safety net used by (mostly custom) function descriptors that accept exactly one Java type.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardArgumentsValidators.java:232

					sig.append("arg").append(i);
				}
				sig.append("])");
				return sig.toString();
			}
		};
	}

	public static ArgumentsValidator of(Class<?> javaType) {
		return new ArgumentsValidator() {
			@Override
			public void validate(
					List<? extends SqmTypedNode<?>> arguments,
					String functionName,
					BindingContext bindingContext) {
				for ( var argument : arguments ) {
					var argType = argument.getNodeJavaType().getJavaTypeClass();
					if ( !javaType.isAssignableFrom( argType ) ) {
						throw new FunctionArgumentException(
								String.format(
										Locale.ROOT,
										"Function %s() has parameters of type %s, but argument of type %s given",
										functionName,
										javaType.getName(),
										argType.getName()
								)
						);
					}
				}
			}
		};
	}

	public static ArgumentsValidator composite(ArgumentsValidator... validators) {
		return composite( asList( validators ) );
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass an argument whose Java type is assignable to the required type - the message names the expected class and the actual class.
  2. Rebind the parameter with the matching Java type or switch to the correctly typed entity attribute.
  3. If the coercion is intentional, wrap the argument in an HQL cast(): cast(p.name as int).
  4. If the function must accept several types, register it with a different validator (e.g. between(...) plus explicit cast handling) instead of of(Class).

Example fix

// before - descriptor registered with StandardArgumentsValidators.of(Integer.class)
select myNumFunc(p.name) from Person p

// after - use the numeric attribute, or cast explicitly
select myNumFunc(p.age) from Person p
select myNumFunc(cast(p.name as int)) from Person p
Defensive patterns

Strategy: validation

Validate before calling

// before creating the query, check the Java types you will bind
static boolean allAssignableTo(Class<?> required, Class<?>... actual) {
    for (Class<?> c : actual) {
        if (!required.isAssignableFrom(c)) return false;
    }
    return true;
}
if (!allAssignableTo(Integer.class, String.class)) {
    throw new IllegalArgumentException("myNumFunc requires Integer-typed arguments");
}

Type guard

static boolean hasJavaType(SqmTypedNode<?> node, Class<?> required) {
    var jt = node.getNodeJavaType();
    return jt != null && required.isAssignableFrom(jt.getJavaTypeClass());
}

Try / catch

try {
    em.createQuery(hql).getResultList();
} catch (org.hibernate.query.sqm.produce.function.FunctionArgumentException e) {
    // message names the expected and actual Java types
    throw new IllegalArgumentException("Wrong argument type in HQL function call: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: A function registered with StandardArgumentsValidators.of(Integer.class) invoked with a String-typed path or literal, e.g. select my_num_func(p.name) where p.name is a String attribute; or binding a parameter with the wrong Java type (setString into a numeric-only function argument).

Common situations: Custom FunctionContributor descriptors written for one Java type then reused against differently-typed entity attributes; an entity field type changed (Integer to String) without updating queries; passing quoted literals ('1') where a numeric type is required.

Related errors


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