hibernate/hibernate-orm · error · SyntaxException

At {}:{} and token '{}', {}

Error message

At {}:{} and token '{}', {}

What it means

Error "At {}:{} and token '{}', {}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/OrderByFragmentTranslator.java:93

		catch (ParseCancellationException e) {
			// When resetting the parser, its CommonTokenStream will seek(0) i.e. restart emitting buffered tokens.
			// This is enough when reusing the lexer and parser, and it would be wrong to also reset the lexer.
			// Resetting the lexer causes it to hand out tokens again from the start, which will then append to the
			// CommonTokenStream and cause a wrong parse
			// lexer.reset();

			// reset the input token stream and parser state
			parser.reset();

			// fall back to LL(k)-based parsing
			parser.getInterpreter().setPredictionMode( PredictionMode.LL );
//			parser.addErrorListener( ConsoleErrorListener.INSTANCE );
			parser.setErrorHandler( new DefaultErrorStrategy() );

			final ANTLRErrorListener errorListener = new BaseErrorListener() {
				@Override
				public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
					throw new SyntaxException( prettifyAntlrError( offendingSymbol, line, charPositionInLine, msg, e, fragment, true ), fragment );
				}
			};
			parser.addErrorListener( errorListener );

			return parser.orderByFragment();
		}
		catch ( ParsingException ex ) {
			// Note that this is supposed to represent a bug in the parser
			throw new QueryException( "Failed to interpret syntax [" + ex.getMessage() + "]", fragment, ex );
		}
	}

}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Fix the @OrderBy fragment syntax: use valid domain-model paths, '.' navigation, and optional ASC/DESC.
  2. Check the token reported in the message against the allowed ordering grammar.

When it happens

Trigger: Thrown when parsing an @OrderBy fragment fails at the reported line/column and token, e.g. due to a syntax error in the ordering expression.

Common situations: See trigger scenarios.


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