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
- Cast or bind the bounds to a concrete type: cast(:a as integer) or setParameter("a", 1, Integer.class)
- Use typed literals for series bounds
- Upgrade Hibernate for improved SQL Server series type resolution
- 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
- Use cast(:a as integer) around parameterized series bounds on SQL Server
- Prefer a numbers/sequence table for heavy series usage on SQL Server
- Keep Hibernate current for improved SQL Server series emulation
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
- Couldn't determine types of arguments to function 'generate_
- Couldn't determine types of arguments to function 'generate_
- Couldn't determine types of arguments to function 'generate_
- Start and stop parameters of function '%s()' must be of the
- Step parameter of function '%s()' is of type '%s', but must
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ef4e0439b1bf9aba.
Report an issue: GitHub.