hibernate/hibernate-orm · error · FunctionArgumentException

Function argument [%s] of type [%s] at specified position [%

Error message

Function argument [%s] of type [%s] at specified position [%d] in call arguments was not typed as an allowable function return type

What it means

extractArgumentType(arguments, position) is the helper behind useArgType(...) return-type resolvers: it takes the type of the argument at the given 1-based position and reuses it as the function's return type. If that argument's SqmExpressible is non-null but not a ReturnableType (i.e. it cannot be produced as a function result), it throws FunctionArgumentException while the query is interpreted. This is a function-authoring mismatch: the chosen argument position cannot drive the return type.

Source

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

			//type specified in the function template (i.e. in the Dialect) and a type
			//that is determined by how the function is used in the HQL query. In essence
			//the types are compatible if the map to the same JDBC type, of if they are
			//both numeric types.
			return isAssignableTo( defined.getJdbcMapping(), implied.getJdbcMapping() );
		}
	}

	public static ReturnableType<?> extractArgumentType(List<? extends SqmTypedNode<?>> arguments, int position) {
		final SqmTypedNode<?> specifiedArgument = arguments.get( position - 1 );
		final SqmExpressible<?> specifiedArgType = getArgumentExpressible( specifiedArgument );
		if ( specifiedArgType == null ) {
			return null;
		}
		else if ( specifiedArgType instanceof ReturnableType<?> returnableType ) {
			return returnableType;
		}
		else {
			throw new FunctionArgumentException(
					String.format(
							Locale.ROOT,
							"Function argument [%s] of type [%s] at specified position [%d] in call arguments was not typed as an allowable function return type",
							specifiedArgument,
							specifiedArgType,
							position
					)
			);
		}
	}

	private static SqmExpressible<?> getArgumentExpressible(SqmTypedNode<?> specifiedArgument) {
		final SqmExpressible<?> expressible = specifiedArgument.getExpressible();
		return expressible != null ? expressible.getSqmType() : null;
	}

//	public static JdbcMapping extractArgumentJdbcMapping(
//			TypeConfiguration typeConfiguration,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Point useArgType at an argument position that is basic-typed (String, Integer, ...).
  2. Force the input shape with an HQL cast(): my_func(cast(e.embeddedField as string)).
  3. If the return type does not really depend on an argument, use invariant(...) with a fixed type instead.
  4. Dereference to a basic attribute before passing: my_func(e.embedded.someField).

Example fix

// before - arg 1 is an embeddable path, not a ReturnableType
resolverBuilder.useArgType("value", 1)

// after - fixed return type; argument shape no longer matters
resolverBuilder.invariant("value", StandardBasicTypes.STRING)
Defensive patterns

Strategy: try-catch

Validate before calling

static boolean argumentIsReturnable(List<? extends SqmTypedNode<?>> arguments, int position) {
    if (arguments.size() < position) return false;
    return arguments.get(position - 1).getNodeType() instanceof ReturnableType;
}

Try / catch

try {
    return em.createQuery(hql).getResultList();
} catch (org.hibernate.query.sqm.produce.function.FunctionArgumentException e) {
    log.error("Function argument not usable as return type: {}", e.getMessage());
    throw e;
}

Prevention

When it happens

Trigger: A custom function (often set-returning, built with SetReturningFunctionTypeResolverBuilder.useArgType(component, pos)) whose referenced argument resolves to a non-returnable expressible - e.g. an entity-typed or embedded-typed path - so extractArgumentType hits the else branch.

Common situations: Reusing a working function template against a new entity whose attribute at that position is an embeddable or association; changing an attribute from basic to embedded and forgetting the function definition; building generate_series/unnest-style functions where the argument position drifted after an edit.

Related errors


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