hibernate/hibernate-orm · error · IllegalArgumentException

Couldn't determine types of arguments to function 'generate_

Error message

Couldn't determine types of arguments to function 'generate_series'

What it means

NumberSeriesGenerateSeriesFunction is the generic numeric generate_series implementation shared by many dialects. While resolving the function's return type it coalesces the expression types of the series bounds; if no single JdbcMapping results, it throws. As in the shared resolver, this build reads arguments.get(0) for both 'start' and 'stop', so the stop argument's type is never consulted.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/NumberSeriesGenerateSeriesFunction.java:348

		protected SelectableMapping[] resolveIterationVariableBasedFunctionReturnType(
				List<? extends SqlAstNode> arguments,
				String tableIdentifierVariable,
				boolean lateral,
				boolean withOrdinality,
				SqmToSqlAstConverter converter) {
			final Expression start = (Expression) arguments.get( 0 );
			final Expression stop = (Expression) arguments.get( 0 );
			final JdbcMappingContainer expressionType = NullnessHelper.coalesce(
					start.getExpressionType(),
					stop.getExpressionType()
			);
			final Expression explicitStep = arguments.size() > 2
					? (Expression) arguments.get( 2 )
					: null;
			final JdbcMapping type = expressionType.getSingleJdbcMapping();
			if ( type == null ) {
				throw new IllegalArgumentException(
						"Couldn't determine types of arguments to function 'generate_series'" );
			}

			final SelectableMapping indexMapping = withOrdinality ? new SelectableMappingImpl(
					"",
					defaultIndexSelectionExpression,
					new SelectablePath( CollectionPart.Nature.INDEX.getName() ),
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					false,
					false,
					false,
					false,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Cast/bind the start argument to a concrete type: cast(:a as integer) or setParameter("a", 1, Integer.class)
  2. Upgrade/patch Hibernate so arguments 0 and 1 are both read (this region uses get(0) twice)
  3. Ensure no null or Object-typed series bounds reach the query

Example fix

// before
select s from generate_series(:a, :b) s(serie, idx)

// after
select s from generate_series(cast(:a as integer), cast(:b as integer)) s(serie, idx)
Defensive patterns

Strategy: validation

Validate before calling

// Bound the series with concrete types before query creation
static void checkSeriesBounds(Object start, Object stop) {
    if (!(start instanceof Number) || !(stop instanceof Number)) {
        throw new IllegalArgumentException("generate_series bounds must be non-null Numbers");
    }
}

Try / catch

try {
    return em.createQuery(hql, Object[].class).getResultList();
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().contains("generate_series")) {
        return em.createQuery(withCasts(hql), Object[].class).getResultList();
    }
    throw e;
}

Prevention

When it happens

Trigger: generate_series calls where the first argument's expression type carries no single JDBC mapping — untyped parameters, null literals, or Object-typed bindings — on any dialect using the numeric series function.

Common situations: Dynamic HQL builders binding series bounds without explicit types; queries ported from native SQL; Hibernate versions where the duplicated get(0) makes even a properly typed stop argument unable to rescue an untyped start.

Related errors


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