{"record":{"id":"14fdbf4287f4e7eb","repo":"hibernate/hibernate-orm","slug":"cannot-convert-character-value-character","errorCode":null,"errorMessage":"Cannot convert Character value '\" + character + \"' to Boolean","messagePattern":"Cannot convert Character value '\" \\+ character \\+ \"' to Boolean","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java","lineNumber":134,"sourceCode":"\t@Override\n\tpublic <X> Boolean wrap(X value, WrapperOptions options) {\n\t\tif ( value == null ) {\n\t\t\treturn null;\n\t\t}\n\t\tif (value instanceof Boolean booleanValue) {\n\t\t\treturn booleanValue;\n\t\t}\n\t\tif (value instanceof Number number) {\n\t\t\treturn number.intValue() != 0;\n\t\t}\n\t\tif (value instanceof Character character) {\n\t\t\tif ( isTrue( character ) ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( isFalse( character ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthrow new IllegalArgumentException( \"Cannot convert Character value '\" + character + \"' to Boolean\" );\n\t\t}\n\t\tif (value instanceof String string) {\n\t\t\tif ( isTrue( string ) ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( isFalse( string ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthrow new IllegalArgumentException( \"Cannot convert value '\" + string + \"' to Boolean\" );\n\t\t}\n\t\tthrow unknownWrap( value.getClass() );\n\t}\n\n\tprivate boolean isTrue(String strValue) {\n\t\treturn strValue != null\n\t\t\t&& !strValue.isEmpty()\n\t\t\t&& isTrue( strValue.charAt(0) );\n\t}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java#L116-L152","documentation":"BooleanJavaType.wrap(value) accepts a Character only when it equals the configured true/false characters. With the default constructor those are 'Y'/'y' and 'N'/'n'; any other character ('T', 'F', '1', '0', 'X', ...) throws IllegalArgumentException because the value cannot be interpreted as a Boolean.","triggerScenarios":"Binding a Character parameter to a boolean attribute in HQL/Criteria; a char(1) column storing T/F or 0/1 flags mapped straight to a Boolean field without a converter; data written under a different boolean character convention than the mapping expects.","commonSituations":"Porting a schema designed for another ORM that used 'T'/'F'; legacy databases with 0/1 character flags; switching dialect or boolean literal settings while old data keeps the previous encoding.","solutions":["Add an AttributeConverter that maps the actual stored characters ('T'/'F', '0'/'1') to Boolean.","Migrate the column data to the 'Y'/'N' convention the descriptor expects.","Register a BooleanJavaType variant with the correct true/false characters (via a custom BasicType) if the whole schema uses a different encoding.","Bind real Boolean objects in queries instead of Characters."],"exampleFix":"// before: column holds 'T'/'F'\n@Basic private Boolean active; // wrap('T') -> IllegalArgumentException\n\n// after\n@Convert(converter = TfBooleanConverter.class)\nprivate Boolean active;\n...\npublic class TfBooleanConverter implements AttributeConverter<Boolean, Character> {\n    public Character convertToDatabaseColumn(Boolean b) { return b ? 'T' : 'F'; }\n    public Boolean convertToEntityAttribute(Character c) { return c == 'T'; }\n}","handlingStrategy":"validation","validationCode":"static boolean isBooleanChar(char c) {\n    char u = Character.toUpperCase(c);\n    return u == 'Y' || u == 'N'; // default BooleanJavaType convention\n}","typeGuard":"static Boolean toBooleanOrNull(char c) {\n    char u = Character.toUpperCase(c);\n    if (u == 'Y') return Boolean.TRUE;\n    if (u == 'N') return Boolean.FALSE;\n    return null; // would throw in BooleanJavaType.wrap\n}","tryCatchPattern":null,"preventionTips":["Store booleans as 'Y'/'N' or use a native boolean/integer column.","Add an AttributeConverter whenever the DB encoding differs from Y/N.","Bind Boolean parameters, never Character, in HQL/Criteria."],"tags":["hibernate","boolean","character","mapping","conversion"],"backgroundTag":"boolean-value-conversion","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}