Issue when trying to use the IN operator in a JPQL query

◇◆丶佛笑我妖孽 提交于 2019-12-11 13:15:01

问题


the following query :

SELECT P FROM Project P WHERE :currentUser IN(P.assignedUsers)

throws the following error :

org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement: "...."; expected "NOT, EXISTS, INTERSECTS, SELECT, FROM";

Am i using the IN operator wrong, or am i supposed to do it differently.

Project.assignedUsers : is a list containing users (a OneToMany Relationship). and the currentUser parameter is a valid user.


回答1:


You cannot use implicit joins for this purpose; you probably want to utilize the member of operator:

SELECT P FROM Project P WHERE :currentUser MEMBER OF P.assignedUsers


来源:https://stackoverflow.com/questions/32631930/issue-when-trying-to-use-the-in-operator-in-a-jpql-query

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