hibernate/hibernate-orm · error · UnsupportedOperationException
The function {name} is not a window function
Error message
The function {name} is not a window function What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/function/AbstractSqmSelfRenderingFunctionDescriptor.java:162
withinGroupClause,
impliedResultType,
getArgumentsValidator(),
getReturnTypeResolver(),
queryEngine.getCriteriaBuilder(),
getName()
);
}
@Override
protected <T> SelfRenderingSqmWindowFunction<T> generateSqmWindowFunctionExpression(
List<? extends SqmTypedNode<?>> arguments,
SqmPredicate filter,
Boolean respectNulls,
Boolean fromFirst,
ReturnableType<T> impliedResultType,
QueryEngine queryEngine) {
if ( functionKind != FunctionKind.WINDOW ) {
throw new UnsupportedOperationException( "The function " + getName() + " is not a window function" );
}
return new SelfRenderingSqmWindowFunction<>(
this,
this,
arguments,
filter,
respectNulls,
fromFirst,
impliedResultType,
getArgumentsValidator(),
getReturnTypeResolver(),
queryEngine.getCriteriaBuilder(),
getName()
);
}
public static boolean filterClauseSupported(SqlAstTranslator<?> translator) {
return translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();View on GitHub (pinned to fad1729dce)
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.
Example fix
// before
em.createQuery("select concat(e.name, '') over (partition by e.dept) from Employee e"); // UnsupportedOperationException
// after
em.createQuery("select rowNumber() over (partition by e.dept order by e.salary) from Employee e"); Defensive patterns
Strategy: validation
Validate before calling
var f = sessionFactory.getQueryEngine().getSqmFunctionRegistry().findFunction("my_func");
if (f == null || f.getFunctionKind() != org.hibernate.query.sqm.function.FunctionKind.WINDOW) {
// 'my_func(...) over (...)' will fail — use rowNumber/rank/lead/lag or register with FunctionKind.WINDOW
} Try / catch
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; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The function {name} is not an aggregate function
- The function {name} is not an ordered set-aggregate function
- Can't emulate [%s] in clause %s. Only the SELECT clause is s
- Can't emulate [%s] in clause %s. Only the SELECT clause is s
- Entity discriminator cannot be de-referenced
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/59c3854c579460db.
Report an issue: GitHub.