0

We dont use hibernate propriety API. We follow pure JPA standard API. How to set a boolean value as parameter to JPQL query?(javax.persistenc.Query) the following is not working

    @NamedQuery(name = "Employee.getEmployeeByState", query = "select employee.id From Employee employee where employee.state=:inputState")


    Query getEmployeesExcluded = entityManager.createNamedQuery("Employee.getEmployeeByState");
    getEmployeesExcluded .setParameter("inputState", Boolean.FALSE);
user2555212
  • 165
  • 1
  • 14

1 Answers1

-1

The problem could happen because in your entity you should have the state attribute as boolean, but in your database it should be tinyint or int or something like that (since we don't know your entity I am assuming that), so probably you should use a typeConverter:

@Entity
@NamedQuery(name = "Employee.getEmployeeByState", query = "select employee.id From Employee employee where employee.state=:inputState")
public class Employee implements Serializable {

    @TypeConverter(name="intToBoolean", dataType=Integer.class, objectType=Boolean.class)
    private boolean state;

    //getters and setters
}

here you can find more information about that annotation.

EDIT:

Or you can implement your own converter, check this, this and this

Dazak
  • 1,011
  • 2
  • 9
  • 17