hibernate/hibernate-orm · error · ParsingException
Unrecognized trim specification
Error message
Unrecognized trim specification
What it means
Thrown by SemanticQueryBuilder.trimSpec when the trim specification token of a trim() call matches neither 'leading', 'trailing' nor 'both'. It is an internal token-switch default (UnsupportedOperationException) — with a matching grammar it is unreachable and signals a parser/grammar mismatch in trim specification parsing.
Solutions
- The trim specification is not recognized. Use LEADING, TRAILING, or BOTH in the trim() function.
Defensive patterns
Strategy: validation
When it happens
Trigger: An invalid keyword/field is used in a datetime, pad, or trim expression: Unrecognized trim specification
Common situations: HQL queries using extract(), pad(), or trim() with a field/specification keyword that is not one of the documented values.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c4bfeb85a3e0b440.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:5548
null,
queryEngine()
);
}
@Override
public SqmTrimSpecification visitTrimSpecification(HqlParser.TrimSpecificationContext ctx) {
// JPA says the default is BOTH
final var trimSpec = ctx != null ? trimSpec( ctx ) : TrimSpec.BOTH;
return new SqmTrimSpecification( trimSpec, nodeBuilder() );
}
private static TrimSpec trimSpec(HqlParser.TrimSpecificationContext ctx) {
final var symbol = ((TerminalNode) ctx.getChild( 0 )).getSymbol();
return switch ( symbol.getType() ) {
case HqlParser.LEADING -> TrimSpec.LEADING;
case HqlParser.TRAILING -> TrimSpec.TRAILING;
case HqlParser.BOTH -> TrimSpec.BOTH;
default -> throw new ParsingException( "Unrecognized trim specification" );
};
}
@Override
public SqmExpression<Character> visitTrimCharacter(HqlParser.TrimCharacterContext ctx) {
final String trimCharText;
if ( ctx == null ) {
// JPA says space is the default
trimCharText = " ";
}
else {
final var parameter = ctx.parameter();
if ( parameter != null ) {
//noinspection unchecked
return (SqmExpression<Character>) parameter.accept( this );
}
else {
trimCharText = unquoteStringLiteral( ctx.getText() );View on GitHub (pinned to fad1729dce)