{"record":{"id":"df8c2a963df2579f","repo":"hibernate/hibernate-orm","slug":"trim-character-for-trim-function-must-be-single","errorCode":null,"errorMessage":"Trim character for trim() function must be single character, found '{trimCharText}'","messagePattern":"Trim character for trim\\(\\) function must be single character, found '(.+?)'","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":5568,"sourceCode":"\t}\n\n\t@Override\n\tpublic SqmExpression<Character> visitTrimCharacter(HqlParser.TrimCharacterContext ctx) {\n\t\tfinal String trimCharText;\n\t\tif ( ctx == null ) {\n\t\t\t// JPA says space is the default\n\t\t\ttrimCharText = \" \";\n\t\t}\n\t\telse {\n\t\t\tfinal var parameter = ctx.parameter();\n\t\t\tif ( parameter != null ) {\n\t\t\t\t//noinspection unchecked\n\t\t\t\treturn (SqmExpression<Character>) parameter.accept( this );\n\t\t\t}\n\t\t\telse {\n\t\t\t\ttrimCharText = unquoteStringLiteral( ctx.getText() );\n\t\t\t\tif ( trimCharText.length() != 1 ) {\n\t\t\t\t\tthrow new SemanticException( \"Trim character for trim() function must be single character, found '\"\n\t\t\t\t\t\t\t+ trimCharText + \"'\",\n\t\t\t\t\t\t\tquery );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn new SqmLiteral<>(\n\t\t\t\ttrimCharText.charAt( 0 ),\n\t\t\t\tnodeBuilder().getCharacterType(),\n\t\t\t\tnodeBuilder()\n\t\t);\n\t}\n\n\t@Override\n\tpublic SqmCollectionSize visitCollectionSizeFunction(HqlParser.CollectionSizeFunctionContext ctx) {\n\t\treturn new SqmCollectionSize(\n\t\t\t\tconsumeDomainPath( (HqlParser.PathContext) ctx.getChild( 2 ) ),\n\t\t\t\tnodeBuilder().getIntegerType(),\n\t\t\t\tnodeBuilder()","sourceCodeStart":5550,"sourceCodeEnd":5586,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L5550-L5586","documentation":"Error \"Trim character for trim() function must be single character, found '{trimCharText}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A multi-character literal is passed where a single character is required: Trim character for trim() function must be single character, found '<value>'","commonSituations":"Calling pad() or trim() in HQL with a pad/trim character literal longer than one character.","solutions":["The trim character argument of trim() must be a single character. Pass a single-character string literal."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}