如何在 hql hibernate 和 spring boot 中使用布尔属性

How to work with boolean attributes in hql hibernate and spring boot

这是我的 hql 代码:

@Query("select a from Agent where a.visibility = true a order by a.id desc")
public Page<Agent> getAllAgents(Pageable pageable);

我想 select 所有可见性为 true 的代理。

在我的代理中 class 我有布尔可见性属性,它在数据库中存储为位 (1)。

我试过了: a.visibility = true, ... = 'true', ... is true, = 1, = '1' ,....

但是得到这个错误:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: a near line 1, column 74 [select a from com.GemCrmTickets.entities.Agent where a.visibility = true a order by a.id desc]

请提出任何建议。先感谢您。提前谢谢你。

查询格式错误,应该是:

@Query("select from Agent a where a.visibility = true a order by a.id desc")

您将实体实例绑定到变量 a,语法要求它在实体之后声明。在标准 SQL.

中是一样的