I’m using Mysql 8 database for my project and org.hibernate.orm with 6.4.4.Final version. I’m using tinyInt for boolean columns. In my entity class I have mapped to boolean for tinyInt column. Now on running a HQL query with checking the boolean field with 1 it gives exception like “java.lang.IllegalArgumentException: org.hibernate.query.SemanticException: Cannot compare left expression of type ‘java.lang.Boolean’ with right expression of type 'java.lang.Integer’”.
I have using a attributeConvertor for Boolean fields to tinyInt. It is working though.
I’m facing the problem with boolean to tinyInt.
Comparison expressions against literals and / or parameters are aware of the underlying Attribute Converter. You should be able to directly compare your converted field against true
/ false
in you HQL, and Hibernate should take care of the conversion.
Is it better to change the queries to add true/false
instead of 1 or 0
for primitve boolean fields.
Yes, that is the supported way to compare against converted fields.
Thank you for quick reply