hibernate/hibernate-orm · error · UnsupportedOperationException

Unrecognized null precedence: " +…

Error message

Unrecognized null precedence: " + nullsPrecedenceContext.getText()

What it means

Thrown while parsing a CTE 'search' specification's null precedence in SemanticQueryBuilder: the nulls-precedence token is neither 'nulls first' nor 'nulls last'. Like the sort-order fallback next to it, this is an internal completeness guard (UnsupportedOperationException) reached only when the parser hands back an unexpected nulls-precedence context.

Solutions

  1. Use 'nulls first' or 'nulls last' for null precedence.
  2. Fix the order-by clause syntax.
Defensive patterns

Strategy: validation

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/e54270cfcbffcc32. Report an issue: GitHub.

Appendix: source

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

			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 );
	}

	private static CteSearchClauseKind getCteSearchClauseKind(HqlParser.SearchClauseContext ctx) {
		return ctx.BREADTH() != null ? CteSearchClauseKind.BREADTH_FIRST : CteSearchClauseKind.DEPTH_FIRST;
	}

	@Override
	public SqmQueryPart<?> visitQueryOrderExpression(HqlParser.QueryOrderExpressionContext ctx) {
		final var sqmQuerySpec = currentQuerySpec();
		final var fromClause = buildInferredFromClause(null);
		sqmQuerySpec.setFromClause( fromClause );

View on GitHub (pinned to fad1729dce)