I'm using Spring Boot and Hibernate and when running my tests in H2 (2.1.210) I get an Values of types "BOOLEAN" and "INTEGER" are not comparable error. This is due to a @Query comparing a boolean to an integer. This works in Oracle correctly.
@Query("FROM TABLE_NAME t WHERE t.value= 0")
public List<Example> findExample();
t.value is of type Boolean.
I've found other questions with similar issues and the recommendation is to add this.
import org.hibernate.dialect.H2Dialect;
public class H2DialectExtended extends H2Dialect {
@Override
public String toBooleanValueString(boolean bool) {
return bool ? "TRUE" : "FALSE";
}
}
However this doesn't work.
How can I solve this?
H2/Hibernate Settings - application.yml
spring:
driver:
class-name: org.h2.Driver
datasource:
platform:
url: jdbc:h2:mem:project_name;DB_CLOSE_ON_EXIT=FALSE;MODE=Oracle;
username: username
password:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
BOOLEANdata type in SQL. It does have aBOOLEANdata type in PL/SQL (but your query appears to be SQL and not PL/SQL).t.valueto0or1. It just doesn't work in H2.BOOLEANdata type in SQL so, inside the database, you are probably comparing an integer to an integer.valueis of typeBoolean. In the database it will be stored as0or1but Hibernate must be mapping it based on the dialect. I believe my statement is correct as I'm not saying Oracle has a boolean type. I'm saying that my code is essentially running"TRUE" = 1instead of mapping the values first. When executed in Oracle it runs1 = 1as expected. I've updated my question to make it clearer.