【问题标题】:How to work with boolean attributes in hql hibernate and spring boot [duplicate]如何在hql hibernate和spring boot中使用布尔属性[重复]
【发布时间】:2017-08-23 13:16:44
【问题描述】:

这是我的 hql 代码:

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

我想选择所有可见性为真的代理。

在我的代理类中,我有布尔可见性属性,它在数据库中存储为 bit(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]

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

【问题讨论】:

  • 您的查询中有错字,错误非常明确:unexpected token: a。删除a.visibility = true 之后和order by 之前的a。它应该可以工作。
  • 不要一遍又一遍地问同一个问题...stackoverflow.com/questions/45840854/…

标签: hibernate spring-boot hql


【解决方案1】:

查询格式错误,应该是:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-30
    • 2014-07-12
    • 2014-10-17
    • 1970-01-01
    • 2010-10-11
    • 2020-10-17
    • 2014-01-29
    相关资源
    最近更新 更多