{"record":{"id":"dc4a39dfbd6a5f6f","repo":"hibernate/hibernate-orm","slug":"couldn-t-determine-types-of-arguments-to-function-dc4a39","errorCode":null,"errorMessage":"Couldn't determine types of arguments to function 'generate_series'","messagePattern":"Couldn't determine types of arguments to function 'generate_series'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/H2GenerateSeriesFunction.java","lineNumber":154,"sourceCode":"\t\t\tfinal Expression start = (Expression) arguments.get( 0 );\n\t\t\tfinal Expression stop = (Expression) arguments.get( 1 );\n\t\t\tfinal JdbcMappingContainer expressionType = NullnessHelper.coalesce(\n\t\t\t\t\tstart.getExpressionType(),\n\t\t\t\t\tstop.getExpressionType()\n\t\t\t);\n\t\t\tfinal Expression explicitStep = arguments.size() > 2\n\t\t\t\t\t? (Expression) arguments.get( 2 )\n\t\t\t\t\t: null;\n\t\t\tfinal ColumnReference joinBaseColumnReference = NullnessHelper.coalesce(\n\t\t\t\t\tstart.getColumnReference(),\n\t\t\t\t\tstop.getColumnReference(),\n\t\t\t\t\texplicitStep != null\n\t\t\t\t\t\t\t? explicitStep.getColumnReference()\n\t\t\t\t\t\t\t: null\n\t\t\t);\n\t\t\tfinal JdbcMapping type = expressionType.getSingleJdbcMapping();\n\t\t\tif ( type == null ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Couldn't determine types of arguments to function 'generate_series'\" );\n\t\t\t}\n\n\t\t\tif ( joinBaseColumnReference != null || withOrdinality || type.getJdbcType().isTemporal() ) {\n\t\t\t\treturn resolveIterationVariableBasedFunctionReturnType( arguments, tableIdentifierVariable, lateral, withOrdinality, converter );\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn super.resolveFunctionReturnType( arguments, tableIdentifierVariable, lateral, withOrdinality, converter );\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tprotected void renderGenerateSeries(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tExpression start,\n\t\t\tExpression stop,\n\t\t\t@Nullable Expression step,\n\t\t\tAnonymousTupleTableGroupProducer tupleType,","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/H2GenerateSeriesFunction.java#L136-L172","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (H2)\nem.createQuery(\"select s from generate_series(:a, :b) s(serie, idx)\", Object[].class);\n\n// after\nem.createQuery(\"select s from generate_series(cast(:a as integer), cast(:b as integer)) s(serie, idx)\", Object[].class);","handlingStrategy":"validation","validationCode":"// In H2-based tests, always bind series bounds with explicit types\nq.setParameter(\"from\", from, Integer.class);\nq.setParameter(\"to\", to, Integer.class);","typeGuard":null,"tryCatchPattern":"try {\n    return em.createQuery(hql, Object[].class).getResultList();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"generate_series\")) {\n        throw new IllegalStateException(\"H2 could not type the generate_series bounds; use cast()\", e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["hibernate","h2","generate-series","type-inference","testing"],"backgroundTag":"untyped-query-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}