1

I have a property created like this in my model:

 public class Client {
    private Boolean supervisor;
 }

When doing a query using Criteria, for example: p4 = cb.isTrue (root.get ("supervisor")), JPA returns an error client0_.supervisor = 1 - ERROR: conversion error of string "1" [SQLState: 22018, ISC error code: 335544334]. How can I solve this?

My RDBMS is Firebird and the supervisor column is of type BOOLEAN.

3
  • 1
    What is the type of the column in the database? If its a varchar, you will need a converter to turn it into a boolean. (Or change the type of the column) Commented Oct 5, 2018 at 13:53
  • My RDBMS is Firebird and the supervisor column is of type BOOLEAN. Commented Oct 5, 2018 at 13:55
  • jpa reads and writes correctly in the database field, the problem is only in the where of the Criteria Commented Oct 5, 2018 at 14:16

2 Answers 2

1

It is kind of hard to tell with the information given, but what is probably happening is that your implementation of JPA is hibernate, and hibernate probably has no dialect for Firebase, so you are using some other dialect instead, (like H2 dialect,) and this dialect probably does not handle the boolean data type correctly.

You need to first verify that this is indeed the case, and if so, you will need to either find, or implement, a Hibernate dialect for Firebase that fixes this. It is certainly more work than just tweaking a setting, but it does not require a herculean effort, look here for an example:

HSQL + Hibernate Exception: Wrong column type: Found: double, expected: float

Sign up to request clarification or add additional context in comments.

3 Comments

Looks like Hibernate 5 supports Firebird. However, OP might still be using the wrong dialect. docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/…
I already use in my persistence.xml : <property name="hibernate.dialect" value="org.hibernate.dialect.FirebirdDialect"/>
Okay, then perhaps the dialect is lame and it does not handle booleans well, so you might want to consider fixing it. That's not unheard of, it is precisely what the post I linked to does with an HSQL dialect that does not work correctly with doubles and floats. But wait a couple of days to see if anyone has a better idea. Or try some database other than Firebird, to see if the problem is with Firebird & its dialect, or somehow with your stuff.
0

I have managed to solve the problem, not with Criteria, but with JPQL, as follows:

select     new Extensionista(e.id, e.name) 
from       Extensionista e 
join       e.localControle lc 
where      lc.id =: id 
and        e.cpf is not null 
and        e.status = 'T' 
and        e.supervisor = 'true'
order by   e.name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.