{"record":{"id":"59c3854c579460db","repo":"hibernate/hibernate-orm","slug":"the-function-name-is-not-a-window-function","errorCode":null,"errorMessage":"The function {name} is not a window function","messagePattern":"The function (.+?) is not a window function","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java","lineNumber":162,"sourceCode":"\t\t\t\twithinGroupClause,\n\t\t\t\timpliedResultType,\n\t\t\t\tgetArgumentsValidator(),\n\t\t\t\tgetReturnTypeResolver(),\n\t\t\t\tqueryEngine.getCriteriaBuilder(),\n\t\t\t\tgetName()\n\t\t);\n\t}\n\n\t@Override\n\tprotected <T> SelfRenderingSqmWindowFunction<T> generateSqmWindowFunctionExpression(\n\t\t\tList<? extends SqmTypedNode<?>> arguments,\n\t\t\tSqmPredicate filter,\n\t\t\tBoolean respectNulls,\n\t\t\tBoolean fromFirst,\n\t\t\tReturnableType<T> impliedResultType,\n\t\t\tQueryEngine queryEngine) {\n\t\tif ( functionKind != FunctionKind.WINDOW ) {\n\t\t\tthrow new UnsupportedOperationException( \"The function \" + getName() + \" is not a window function\" );\n\t\t}\n\t\treturn new SelfRenderingSqmWindowFunction<>(\n\t\t\t\tthis,\n\t\t\t\tthis,\n\t\t\t\targuments,\n\t\t\t\tfilter,\n\t\t\t\trespectNulls,\n\t\t\t\tfromFirst,\n\t\t\t\timpliedResultType,\n\t\t\t\tgetArgumentsValidator(),\n\t\t\t\tgetReturnTypeResolver(),\n\t\t\t\tqueryEngine.getCriteriaBuilder(),\n\t\t\t\tgetName()\n\t\t);\n\t}\n\n\tpublic static boolean filterClauseSupported(SqlAstTranslator<?> translator) {\n\t\treturn translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java#L144-L180","documentation":"OVER (...) window syntax requires the function descriptor to be of FunctionKind.WINDOW. When a non-window function is used with an OVER clause, generateSqmWindowFunctionExpression throws UnsupportedOperationException stating the function is not a window function. This guards SQL validity — scalar functions cannot be windowed.","triggerScenarios":"HQL/Criteria like 'select concat(e.name, '-x') over (partition by e.dept) from Employee e', or 'myFunc(a) over (order by b)' where myFunc was registered as NORMAL/AGGREGATE without WINDOW kind. Raised during SQM interpretation, before SQL generation.","commonSituations":"Custom dialect functions (string or math helpers) used experimentally with OVER; expecting any aggregate with OVER to route through the window path (built-in aggregates are already registered appropriately, user ones are not); porting raw SQL window queries into HQL verbatim.","solutions":["Use a real window function: row_number(), rank(), dense_rank(), lead(), lag(), first_value(), nth_value(), etc.","Register your custom window function with FunctionKind.WINDOW in its descriptor (e.g. NamedSqmFunctionDescriptor constructor).","If the OVER clause was a mistake, remove it; if you need raw window SQL Hibernate cannot express, use a native query."],"exampleFix":"// before\nem.createQuery(\"select concat(e.name, '') over (partition by e.dept) from Employee e\"); // UnsupportedOperationException\n\n// after\nem.createQuery(\"select rowNumber() over (partition by e.dept order by e.salary) from Employee e\");","handlingStrategy":"validation","validationCode":"var f = sessionFactory.getQueryEngine().getSqmFunctionRegistry().findFunction(\"my_func\");\nif (f == null || f.getFunctionKind() != org.hibernate.query.sqm.function.FunctionKind.WINDOW) {\n    // 'my_func(...) over (...)' will fail — use rowNumber/rank/lead/lag or register with FunctionKind.WINDOW\n}","typeGuard":null,"tryCatchPattern":"try { em.createQuery(ql).getResultList(); } catch (UnsupportedOperationException e) { /* 'not a window function': use a registered window function or re-register the descriptor with FunctionKind.WINDOW */ throw e; }","preventionTips":["Register custom window functions with FunctionKind.WINDOW in the dialect.","Use HQL window function names (rowNumber, rank, denseRank, lag, lead) instead of raw lowercase SQL names.","For window SQL Hibernate cannot express, fall back to a native query deliberately."],"tags":["hibernate","hql","sqm","window-function","over-clause","custom-dialect"],"backgroundTag":"sql-function-kind-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}