java - 帮助重写 HQL 查询(Hibernate 查询语言)

标签 java hibernate hql

这里是 HQL 菜鸟。如何在不使用 contains 子句的情况下重写此 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)

关于java - 帮助重写 HQL 查询(Hibernate 查询语言),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2096954/

相关文章:

扩展 java.nio.ByteBuffer 的 Java 循环字节缓冲区

java - 使用 Hibernate 更新表中 'many' 项的计数

hibernate - select * where id = :id and entity manager find() 的区别

java - 对象内的 EJB-QL 查询列表

java - HQL-从 2 个表中选择

java - Cassandra 客户端 Java API

java - Swingx组件提供者: hide component on certain rows

java - 什么时候可以/应该全力使用 ORM 方法?

java - 应用程序在 intellij 中工作,但在构建后不工作

java - 具有两个 ID 的实体