{"record":{"id":"1da55b8076c19a30","repo":"hibernate/hibernate-orm","slug":"couldn-t-determine-types-of-arguments-to-function-1da55b","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/NumberSeriesGenerateSeriesFunction.java","lineNumber":348,"sourceCode":"\n\t\tprotected SelectableMapping[] resolveIterationVariableBasedFunctionReturnType(\n\t\t\t\tList<? extends SqlAstNode> arguments,\n\t\t\t\tString tableIdentifierVariable,\n\t\t\t\tboolean lateral,\n\t\t\t\tboolean withOrdinality,\n\t\t\t\tSqmToSqlAstConverter converter) {\n\t\t\tfinal Expression start = (Expression) arguments.get( 0 );\n\t\t\tfinal Expression stop = (Expression) arguments.get( 0 );\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 JdbcMapping type = expressionType.getSingleJdbcMapping();\n\t\t\tif ( type == null ) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Couldn't determine types of arguments to function 'generate_series'\" );\n\t\t\t}\n\n\t\t\tfinal SelectableMapping indexMapping = withOrdinality ? new SelectableMappingImpl(\n\t\t\t\t\t\"\",\n\t\t\t\t\tdefaultIndexSelectionExpression,\n\t\t\t\t\tnew SelectablePath( CollectionPart.Nature.INDEX.getName() ),\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tnull,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfalse,","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/NumberSeriesGenerateSeriesFunction.java#L330-L366","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nselect s from generate_series(:a, :b) s(serie, idx)\n\n// after\nselect s from generate_series(cast(:a as integer), cast(:b as integer)) s(serie, idx)","handlingStrategy":"validation","validationCode":"// Bound the series with concrete types before query creation\nstatic void checkSeriesBounds(Object start, Object stop) {\n    if (!(start instanceof Number) || !(stop instanceof Number)) {\n        throw new IllegalArgumentException(\"generate_series bounds must be non-null Numbers\");\n    }\n}","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        return em.createQuery(withCasts(hql), Object[].class).getResultList();\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["hibernate","hql","generate-series","type-inference","dialect-function"],"backgroundTag":"untyped-query-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}