【问题标题】:How to pass parameter to @Query annotation with hql如何使用 hql 将参数传递给 @Query 注释
【发布时间】:2018-01-31 23:32:49
【问题描述】:

这是我的 hql 请求:

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

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

在我的代理类中,具有布尔可见性属性以及 getVisibility 和 setVisibility 函数。在我的数据库中存储为 bit(1) 的“可见性”。

我试过 a.visibility = 1, ... = '1', ...= 'TRUE', ...='true', ... 是真的。但我得到这个错误:

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 a from Agent where a.visibility = 1 a order by a.id desc")你不会得到同样的错误
  • 您的查询中true 后面有一个a,这会使查询无效。
  • 不要一遍又一遍地问同一个问题!!!

标签: spring hibernate spring-boot hql


【解决方案1】:

将您的查询更改为:

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

【讨论】:

    【解决方案2】:

    在您的代码中,您必须写下表的 Alice 名称,然后添加它。

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

    【讨论】:

      【解决方案3】:

      您的查询不正确,您在trueorder by... 之间多了一个a。所以正确的查询会变成这样

      select a from Agent a where a.visibility = true order by a.id desc
      

      不确定这是否能解决您的所有问题。看看吧。

      【讨论】:

        猜你喜欢
        • 2017-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-13
        • 2021-12-22
        • 2018-06-11
        相关资源
        最近更新 更多