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
H2's generate_series support routes through H2GenerateSeriesFunction. Before choosing between the iteration-variable emulation and plain rendering it must know the JDBC type of the series; if the coalesced expression type of start/stop/step yields no single JdbcMapping it throws this IllegalArgumentException during SQL rendering.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/H2GenerateSeriesFunction.java:154
final Expression start = (Expression) arguments.get( 0 );
final Expression stop = (Expression) arguments.get( 1 );
final JdbcMappingContainer expressionType = NullnessHelper.coalesce(
start.getExpressionType(),
stop.getExpressionType()
);
final Expression explicitStep = arguments.size() > 2
? (Expression) arguments.get( 2 )
: null;
final ColumnReference joinBaseColumnReference = NullnessHelper.coalesce(
start.getColumnReference(),
stop.getColumnReference(),
explicitStep != null
? explicitStep.getColumnReference()
: null
);
final JdbcMapping type = expressionType.getSingleJdbcMapping();
if ( type == null ) {
throw new IllegalArgumentException( "Couldn't determine types of arguments to function 'generate_series'" );
}
if ( joinBaseColumnReference != null || 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
- Bind series bounds with explicit types or cast them in HQL (cast(:a as integer))
- Use typed literals in tests
- Prefer the production dialect (Testcontainers PostgreSQL) for queries that lean on dialect-specific set-returning functions
- Upgrade Hibernate for improved H2 series type resolution
Example fix
// before (H2)
em.createQuery("select s from generate_series(:a, :b) s(serie, idx)", Object[].class);
// after
em.createQuery("select s from generate_series(cast(:a as integer), cast(:b as integer)) s(serie, idx)", Object[].class); Defensive patterns
Strategy: validation
Validate before calling
// In H2-based tests, always bind series bounds with explicit types
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")) {
throw new IllegalStateException("H2 could not type the generate_series bounds; use cast()", e);
}
throw e;
} Prevention
- Use cast(:a as integer) in HQL intended to run on H2
- Prefer Testcontainers with the production dialect for dialect-specific functions
- Keep test and production Hibernate versions aligned
When it happens
Trigger: Running generate_series on the H2 dialect with start/stop (or step) arguments whose expression type has no single JDBC mapping — untyped parameters, null literals, or non-numeric argument types.
Common situations: Integration tests running against H2 (often in place of PostgreSQL) where the same HQL worked natively; H2 tests with parameterized series bounds; version drift between test (H2) and production dialects.
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_
- Insert conflict 'do update' clause with constraint name is n
- Can't emulate fetch clause type:
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/dc4a39dfbd6a5f6f.
Report an issue: GitHub.