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.

Rodrigo
  • 61
  • 2
  • 6
  • 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) – Carl Shiles Oct 05 '18 at 13:53
  • My RDBMS is Firebird and the supervisor column is of type BOOLEAN. – Rodrigo Oct 05 '18 at 13:55
  • jpa reads and writes correctly in the database field, the problem is only in the where of the Criteria – Rodrigo Oct 05 '18 at 14:16

2 Answers2

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

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
  • 1
    Looks like Hibernate 5 supports Firebird. However, OP might still be using the wrong dialect. https://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/ch03.html#configuration-optional-dialects – Dan W Oct 05 '18 at 14:11
  • 1
    I already use in my persistence.xml : – Rodrigo Oct 05 '18 at 14:14
  • 1
    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. – Mike Nakis Oct 05 '18 at 15:26
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
Rodrigo
  • 61
  • 2
  • 6