我们不使用hibernate propriety API。 我们遵循纯JPA标准API。 如何设置一个布尔值作为JPQL查询的参数?(javax.persistenc.Query) 以下是行不通的
@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);
答案 0 :(得分:-1)
问题可能发生,因为在您的实体中,您应该将state
属性设为boolean
,但在您的数据库中应该是tinyint
或int
或类似的内容(因为我们不知道你所假设的实体),所以你应该使用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您可以找到有关该注释的更多信息。
修改强>