hibernate/hibernate-orm · error · SemanticException

'RESPECT NULLS' or 'IGNORE NULLS' are illegal for function:

Error message

'RESPECT NULLS' or 'IGNORE NULLS' are illegal for function: {functionName}

What it means

Error "'RESPECT NULLS' or 'IGNORE NULLS' are illegal for function: {functionName}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:4748

						query );
			}
			if ( ctx.withinGroupClause() == null && ctx.overClause() == null
					&& functionKind == FunctionKind.ORDERED_SET_AGGREGATE ) {
				throw new SemanticException( "'WITHIN GROUP' or 'OVER' clause is mandatory for ordered set aggregate function: "
						+ functionName,
						query );
			}

			if ( ctx.nullsClause() != null ) {
				switch ( functionName ) {
					case "lag":
					case "lead":
					case "first_value":
					case "last_value":
					case "nth_value":
						break;
					default:
						throw new SemanticException( "'RESPECT NULLS' or 'IGNORE NULLS' are illegal for function: "
								+ functionName,
								query );
				}
			}
			if ( ctx.nthSideClause() != null && !"nth_value".equals( functionName ) ) {
				throw new SemanticException( "'FROM FIRST' or 'FROM LAST' are illegal for function: "
						+ functionName,
						query );
			}
			return functionTemplate;
		}
	}

	private static FunctionKind inferFunctionKind(HqlParser.GenericFunctionContext ctx) {
		if ( ctx.withinGroupClause() != null ) {
			return FunctionKind.ORDERED_SET_AGGREGATE;
		}
		else if ( ctx.overClause() != null ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. RESPECT NULLS / IGNORE NULLS is only valid for the window functions that support it. Remove the clause from this function call.

When it happens

Trigger: An aggregate/window clause is applied to a function that does not accept it: 'RESPECT NULLS' or 'IGNORE NULLS' are illegal for function: <value>

Common situations: HQL queries that attach FILTER, OVER, WITHIN GROUP, RESPECT/IGNORE NULLS, or FROM FIRST/LAST to functions that are not aggregate or window functions, or omit a mandatory OVER/WITHIN GROUP clause.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/5cd064b4494b0348. Report an issue: GitHub.