How to pass parameter to @Query annotation with hql

百般思念 提交于 2019-12-02 22:33:42

问题


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.


回答1:


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.




回答2:


Change your query to this:

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



回答3:


In your code, you have to write the Alice name of the table so add it.

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


来源:https://stackoverflow.com/questions/45838659/how-to-pass-parameter-to-query-annotation-with-hql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!