HQL菜鸟在这里。我如何不使用exist子句来重新编写此HQL查询。在SQL中,我可以只连接VisitorProfileField表和Visitor表,并使用AND添加存在条件。

但是在普通的HQL中,我无法克服某些语法违规。非常感谢您的帮助。

"select distinct v from Visitor v where v.id not in (select o.id from Operator o) " +
      " and exists (select vpf from VisitorProfileField vpf " +
      " where vpf.visitor = v and vpf.profileField.name = :subscription_field " +
      " and vpf.numberVal = :type and vpf.stringVal = :manual) "

最佳答案

我不确定我是否了解您查询的意思,但是我猜是这样的:

select distinct vpf.visitor
from VisitorProfileField vpf
where vpf.profileField.name = :subscription_field
      and vpf.numberVal = :type and vpf.stringVal = :manual
      and vpf.visitor.id not in (select o.id from Operator o)

10-08 01:22