我正在尝试编写HQL查询,以获取属于特定组织或特许运算符(operator)列表中的任何特许运算符(operator)的用户列表,但是 hibernate 无法解析它。我不知道为什么。这是HQL:
from User u where
(u.parentOrganisation = :topLevelOrganisation or u.parentOrganisation in :franchisees)
and u.parentOrganisation.deleted = false
and u.active = true
这是 hibernate 吐出的错误:
unexpected AST node: {vector} [from com.myapp.User u where (u.parentOrganisation = :topLevelOrganisation or u.parentOrganisation in :franchisees0_, :franchisees
1_, :franchisees2_) and u.parentOrganisation.deleted = false and u.active = true]. Stacktrace follows:
Message: unexpected AST node: {vector} [from com.myapp.User u where (u.parentOrganisation = :topLevelOrganisation or u.parentOrganisation in :franchisees0_, :fr
anchisees1_, :franchisees2_) and u.parentOrganisation.deleted = false and u.active = true]
如果我取出
or u.parentOrganisation in :franchisees
位,则查询如下所示:from User u where
(u.parentOrganisation = :topLevelOrganisation)
and u.parentOrganisation.deleted = false
and u.active = true
然后工作正常。我的语法有什么问题?为何 hibernate 提示这个额外条款?
最佳答案
哦,事实证明我需要将:franchisees
括在括号中:
from User u where
(u.parentOrganisation = :topLevelOrganisation or u.parentOrganisation in (:franchisees))
and u.parentOrganisation.deleted = false
and u.active = true