Search code examples
hibernatederbyjpqljavadb

Derby Boolean/Integer conversion in JPQL


The error I get:

ERROR 42821: Columns of type 'BOOLEAN' cannot hold values of type 'INTEGER'.

For the JPQL query:

SELECT b.id FROM Bar b WHERE b.latest = true

Apparently because Hibernate maps a Boolean field (ie "latest) to an integer column for JavaDB/Derby. But this only happens when the column is accessed in JPQL. Same result when using the Criteria API.

Hibernate has been set to org.hibernate.dialect.DerbyDialect and for the driver org.apache.derby.jdbc.EmbeddedDriver.

Same result for other versions of the JDBC driver.

Presumably the workaround is to map the column to a single character containing "Y" and "N". But I'd rather do it properly.

Did anybody encountered this problem too ?


Solution

  • Pass true as query parameter

    SELECT b.id FROM Bar b WHERE b.latest = :latest
    

    will work for sure.