本文介绍了如何使用hql将参数传递给@Query注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的hql请求:

  @Query(从a代理中选择a.visibility = true a.id desc)
public Page< Agent> getAllAgents(可分页);

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



在我的Agent类中,a具有带有getVisibility和setVisibility函数的布尔可见性属性。在我的数据库可见性存储为位(1)。

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

pre $ 原因:org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:近第1行,第74列[从com.GemCrmTickets.entities.Agent中选择一个,其中a.visibility = true通过a.id描述的顺序]

有什么建议吗?您的查询不正确,您有额外的 a 之间 true 按...排序。所以正确的查询会变成这样

 从Agent中选择a a.visibility = true by a.id desc 

不确定是否能解决您的所有问题。检查一下。


Here is my hql requete :

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

I want to select all agents that have visibility true.

In my Agent class a have Boolean visibility attribute with getVisibility and setVisibility functions. In my data base "visibility" stored as bit(1).

I tried a.visibility = 1, ... = '1', ...= 'TRUE', ...='true', ... is true. But i get this error :

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]

Any suggestions ? Thank you in advance.

解决方案

Your query is not correct, you have an extra a between true and order by.... So the correct query would become like this

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

Not sure if that fixes all your troubles. Check it out.

这篇关于如何使用hql将参数传递给@Query注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:16