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

SQLServerGenerateSeriesFunction must decide between the iteration-variable emulation and plain rendering, and that decision needs the JDBC type of the series bounds. If the coalesced expression type of start/stop yields no single JdbcMapping, it throws this IllegalArgumentException during return-type resolution.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerGenerateSeriesFunction.java:129

			super( "value", "value" );
		}

		@Override
		public SelectableMapping[] resolveFunctionReturnType(
				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( 1 );
			final JdbcMappingContainer expressionType = NullnessHelper.coalesce(
					start.getExpressionType(),
					stop.getExpressionType()
			);
			final JdbcMapping type = expressionType.getSingleJdbcMapping();
			if ( type == null ) {
				throw new IllegalArgumentException( "Couldn't determine types of arguments to function 'generate_series'" );
			}

			if ( withOrdinality || type.getJdbcType().isTemporal() ) {
				return resolveIterationVariableBasedFunctionReturnType( arguments, tableIdentifierVariable, lateral, withOrdinality, converter );
			}
			else {
				return super.resolveFunctionReturnType( arguments, tableIdentifierVariable, lateral, withOrdinality, converter );
			}
		}
	}

	@Override
	protected void renderGenerateSeries(
			SqlAppender sqlAppender,
			Expression start,
			Expression stop,
			@Nullable Expression step,
			AnonymousTupleTableGroupProducer tupleType,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Cast or bind the bounds to a concrete type: cast(:a as integer) or setParameter("a", 1, Integer.class)
  2. Use typed literals for series bounds
  3. Upgrade Hibernate for improved SQL Server series type resolution
  4. Prefer a SQL Server-native construct (e.g. a numbers table) for complex series usage

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

// SQL Server: bind series bounds with concrete types before creating the query
q.setParameter("from", from, Integer.class);
q.setParameter("to", to, Integer.class);

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 on the SQL Server dialect with bounds whose expression type has no single JDBC mapping — untyped parameters, null literals, or Object-typed bindings.

Common situations: HQL series queries first developed on PostgreSQL then run against SQL Server; dynamic bounds bound without explicit type classes; SQL Server versions where generate_series is emulated rather than native.

Related errors


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