I have an H2 column of type Boolean but Hibernate query it using a 1
/0
instead of TRUE
/FALSE
values, which leads to the Values of types "BOOLEAN" and "INTEGER" are not comparable
syntax error.
For instance, Hibernate 5 will write
WHERE myBooleanColumn = 1
instead of
WHERE myBooleanColumn = TRUE
How can this be solved?
My H2 database version is 2.0.206 and I'm using Spring Boot 2.5.6.
spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=password spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
– GevMySQL
. Try adding;MODE=PostgreSQL
(or whatever your DB is - many are supported) to your jdbc connection url, iejdbc:h2:...;MODE=PostgreSQL
. btw, what is your jdbc url? – Gevmode.limit=true
hack to not get syntax error on theLIMIT
clause : @Bean @Profile("test") public DataSource dataSource() { // Ref groups.google.com/g/h2-database/c/yxnv64Ak-u8/m/n-kqYV_yBQAJ org.h2.engine.Mode mode = org.h2.engine.Mode.getInstance("ORACLE"); mode.limit = true; DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUrl("jdbc:h2:mem:vessaging;DB_CLOSE_DELAY=-1"); – Biagichar
is used andY
andN
values stored, butnumeric
storing1
and0
is also frequently used. Sounds like H2 picked that later. What datatype is your "boolean" column? – Gevchar
but the entity column type is Boolean. E.g. :@Column(name = "IS_BROADCAST")
private Boolean isBroadcast;
So H2 creates a boolean column. – Biagi