How to pass parameter to @Query annotation with hq

2019-03-06 17:17发布

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.

3条回答
爷、活的狠高调
2楼-- · 2019-03-06 17:38

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")
查看更多
Evening l夕情丶
3楼-- · 2019-03-06 17:52

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);
查看更多
\"骚年 ilove
4楼-- · 2019-03-06 17:53

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.

查看更多
登录 后发表回答