hibernate/hibernate-orm · error · IllegalArgumentException

Cannot convert value '" + string + "' to Boolean

Error message

Cannot convert value '" + string + "' to Boolean

What it means

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').

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaType.java:143

			return number.intValue() != 0;
		}
		if (value instanceof Character character) {
			if ( isTrue( character ) ) {
				return true;
			}
			if ( isFalse( character ) ) {
				return false;
			}
			throw new IllegalArgumentException( "Cannot convert Character value '" + character + "' to Boolean" );
		}
		if (value instanceof String string) {
			if ( isTrue( string ) ) {
				return true;
			}
			if ( isFalse( string ) ) {
				return false;
			}
			throw new IllegalArgumentException( "Cannot convert value '" + string + "' to Boolean" );
		}
		throw unknownWrap( value.getClass() );
	}

	private boolean isTrue(String strValue) {
		return strValue != null
			&& !strValue.isEmpty()
			&& isTrue( strValue.charAt(0) );
	}

	private boolean isFalse(String strValue) {
		return strValue != null
			&& ( strValue.isEmpty() || isFalse( strValue.charAt(0) ) );
	}

	private boolean isTrue(char charValue) {
		return charValue == characterValueTrue
			|| charValue == characterValueTrueLC;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add an AttributeConverter<String,Boolean> that understands the real encoding ('true/false', 'T/F', '1/0').
  2. Migrate the column to 'Y'/'N' text or, better, a native boolean/integer column.
  3. Always pass Boolean objects when binding parameters instead of Strings.

Example fix

// before: column holds 'true'/'false'
@Basic private Boolean enabled; // wrap("true") -> IllegalArgumentException

// after
@Convert(converter = WordBooleanConverter.class)
private Boolean enabled;
...
public class WordBooleanConverter implements AttributeConverter<Boolean, String> {
    public String convertToDatabaseColumn(Boolean b) { return Boolean.TRUE.equals(b) ? "true" : "false"; }
    public Boolean convertToEntityAttribute(String s) { return "true".equalsIgnoreCase(s) || "Y".equalsIgnoreCase(s) || "1".equals(s); }
}
Defensive patterns

Strategy: validation

Validate before calling

static boolean isBooleanString(String s) {
    if (s == null || s.isEmpty()) return true; // empty counts as false
    char c = Character.toUpperCase(s.charAt(0));
    return c == 'Y' || c == 'N';
}

Type guard

static Boolean toBooleanOrNull(String s) {
    if (s == null || s.isEmpty()) return Boolean.FALSE;
    char c = Character.toUpperCase(s.charAt(0));
    if (c == 'Y') return Boolean.TRUE;
    if (c == 'N') return Boolean.FALSE;
    return null;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/9d2dd65080a6e402. Report an issue: GitHub.