When writing a boolean constant to a nullable boolean field, the SQL generated is CASE WHEN 0 THEN 1 ELSE 0 END which is invalid and cause an exception An expression of non-boolean type specified in a context where a condition is expected, near 'THEN'