hibernate/hibernate-orm · error · SemanticException
Trim character for trim() function must be single character,
Error message
Trim character for trim() function must be single character, found '{trimCharText}' What it means
Error "Trim character for trim() function must be single character, found '{trimCharText}'" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:5568
}
@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() );
if ( trimCharText.length() != 1 ) {
throw new SemanticException( "Trim character for trim() function must be single character, found '"
+ trimCharText + "'",
query );
}
}
}
return new SqmLiteral<>(
trimCharText.charAt( 0 ),
nodeBuilder().getCharacterType(),
nodeBuilder()
);
}
@Override
public SqmCollectionSize visitCollectionSizeFunction(HqlParser.CollectionSizeFunctionContext ctx) {
return new SqmCollectionSize(
consumeDomainPath( (HqlParser.PathContext) ctx.getChild( 2 ) ),
nodeBuilder().getIntegerType(),
nodeBuilder()View on GitHub (pinned to fad1729dce)
Solutions
- The trim character argument of trim() must be a single character. Pass a single-character string literal.
When it happens
Trigger: A multi-character literal is passed where a single character is required: Trim character for trim() function must be single character, found '<value>'
Common situations: Calling pad() or trim() in HQL with a pad/trim character literal longer than one character.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/df8c2a963df2579f.
Report an issue: GitHub.