{"record":{"id":"9d2dd65080a6e402","repo":"hibernate/hibernate-orm","slug":"cannot-convert-value-string-to-boolean","errorCode":null,"errorMessage":"Cannot convert value '\" + string + \"' to Boolean","messagePattern":"Cannot convert value '\" \\+ string \\+ \"' to Boolean","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java","lineNumber":143,"sourceCode":"\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}\n\n\tprivate boolean isFalse(String strValue) {\n\t\treturn strValue != null\n\t\t\t&& ( strValue.isEmpty() || isFalse( strValue.charAt(0) ) );\n\t}\n\n\tprivate boolean isTrue(char charValue) {\n\t\treturn charValue == characterValueTrue\n\t\t\t|| charValue == characterValueTrueLC;","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java#L125-L161","documentation":"The String variant of BooleanJavaType.wrap: isTrue(String) requires the first character to be 'Y'/'y'; isFalse(String) accepts an empty string or a first character of 'N'/'n'. Every other input — including 'true', 'false', '1', '0', 'yes' — throws IllegalArgumentException('Cannot convert value ... to Boolean').","triggerScenarios":"Loading a varchar column that holds 'true'/'false' or '0'/'1' text into a Boolean attribute without a converter; setting a String parameter on a boolean-typed HQL predicate; import tools writing literal words into flag columns.","commonSituations":"Schemas shared with applications that store human-readable booleans; CSV or ETL imports; changing a field mapping from String to Boolean without cleaning the data.","solutions":["Add an AttributeConverter<String,Boolean> that understands the real encoding ('true/false', 'T/F', '1/0').","Migrate the column to 'Y'/'N' text or, better, a native boolean/integer column.","Always pass Boolean objects when binding parameters instead of Strings."],"exampleFix":"// before: column holds 'true'/'false'\n@Basic private Boolean enabled; // wrap(\"true\") -> IllegalArgumentException\n\n// after\n@Convert(converter = WordBooleanConverter.class)\nprivate Boolean enabled;\n...\npublic class WordBooleanConverter implements AttributeConverter<Boolean, String> {\n    public String convertToDatabaseColumn(Boolean b) { return Boolean.TRUE.equals(b) ? \"true\" : \"false\"; }\n    public Boolean convertToEntityAttribute(String s) { return \"true\".equalsIgnoreCase(s) || \"Y\".equalsIgnoreCase(s) || \"1\".equals(s); }\n}","handlingStrategy":"validation","validationCode":"static boolean isBooleanString(String s) {\n    if (s == null || s.isEmpty()) return true; // empty counts as false\n    char c = Character.toUpperCase(s.charAt(0));\n    return c == 'Y' || c == 'N';\n}","typeGuard":"static Boolean toBooleanOrNull(String s) {\n    if (s == null || s.isEmpty()) return Boolean.FALSE;\n    char c = Character.toUpperCase(s.charAt(0));\n    if (c == 'Y') return Boolean.TRUE;\n    if (c == 'N') return Boolean.FALSE;\n    return null;\n}","tryCatchPattern":null,"preventionTips":["Never bind raw UI strings to boolean attributes; parse them yourself first.","Keep one boolean encoding per column; enforce with a CHECK constraint.","Add a converter when ingesting data from systems that use 'true'/'false'."],"tags":["hibernate","boolean","string","mapping","conversion"],"backgroundTag":"boolean-value-conversion","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}