hibernate/hibernate-orm · error · UnsupportedOperationException

Unrecognized sort ordering: " + sortCtx.getText()

Error message

Unrecognized sort ordering: " + sortCtx.getText()

What it means

Error "Unrecognized sort ordering: " + sortCtx.getText()" thrown in hibernate/hibernate-orm.

Source

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

						String.format(
								"Search attribute '%s' not found in the CTE %s",
								attributeName,
								cteDefinition.getName()
						),
						query
				);
			}
			SortDirection sortOrder = SortDirection.ASCENDING;
			Nulls nullPrecedence = Nulls.NONE;
			int index = 1;
			if ( index < specCtx.getChildCount() ) {
				if ( specCtx.getChild( index ) instanceof HqlParser.SortDirectionContext ) {
					final var sortCtx = specCtx.sortDirection();
					final var symbol = ((TerminalNode) sortCtx.getChild( 0 )).getSymbol();
					sortOrder = switch ( symbol.getType() ) {
						case HqlParser.ASC -> SortDirection.ASCENDING;
						case HqlParser.DESC -> SortDirection.DESCENDING;
						default -> throw new UnsupportedOperationException(
								"Unrecognized sort ordering: " + sortCtx.getText() );
					};
					index++;
				}
				if ( index < specCtx.getChildCount() ) {
					final var nullsPrecedenceContext = specCtx.nullsPrecedence();
					final var symbol = ((TerminalNode) nullsPrecedenceContext.getChild( 1 )).getSymbol();
					nullPrecedence = switch ( symbol.getType() ) {
						case HqlParser.FIRST -> Nulls.FIRST;
						case HqlParser.LAST -> Nulls.LAST;
						default -> throw new UnsupportedOperationException(
								"Unrecognized null precedence: " + nullsPrecedenceContext.getText() );
					};
				}
			}
			searchOrders.add( nodeBuilder().search( attribute, sortOrder, nullPrecedence ) );
		}
		cteDefinition.search( getCteSearchClauseKind( ctx ), searchAttributeName, searchOrders );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use 'asc' or 'desc' as the sort ordering in the query.
  2. Fix the order-by clause syntax.

When it happens

Trigger: A runtime precondition of the Hibernate API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


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