hibernate/hibernate-orm · error · SemanticException

'FROM FIRST' or 'FROM LAST' are illegal for function: {funct

Error message

'FROM FIRST' or 'FROM LAST' are illegal for function: {functionName}

What it means

Error "'FROM FIRST' or 'FROM LAST' 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:4754

						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 ) {
			return FunctionKind.WINDOW;
		}
		else if ( ctx.filterClause() != null ) {
			return FunctionKind.AGGREGATE;
		}
		else {

View on GitHub (pinned to fad1729dce)

Solutions

  1. FROM FIRST / FROM LAST is only valid for functions like nth_value. 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: 'FROM FIRST' or 'FROM LAST' 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/4cf715c94765968e. Report an issue: GitHub.