{"record":{"id":"ef4e0439b1bf9aba","repo":"hibernate/hibernate-orm","slug":"couldn-t-determine-types-of-arguments-to-function-ef4e04","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/SQLServerGenerateSeriesFunction.java","lineNumber":129,"sourceCode":"\t\t\tsuper( \"value\", \"value\" );\n\t\t}\n\n\t\t@Override\n\t\tpublic SelectableMapping[] resolveFunctionReturnType(\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( 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 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 ( 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":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/SQLServerGenerateSeriesFunction.java#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"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":"// SQL Server: bind series bounds with concrete types before creating the query\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        return em.createQuery(withCasts(hql), Object[].class).getResultList();\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["hibernate","sql-server","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"}