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
- Cast/bind the start argument to a concrete type: cast(:a as integer) or setParameter("a", 1, Integer.class)
- Upgrade/patch Hibernate so arguments 0 and 1 are both read (this region uses get(0) twice)
- 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
- Emit cast() around every parameterized series bound in generated HQL
- Upgrade Hibernate so arguments 0 and 1 are both consulted
- Unit-test generated HQL against the target dialect's parser
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
- 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
- Function %s() requires exactly 3 arguments when invoked with
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/1da55b8076c19a30.
Report an issue: GitHub.