小编Tor*_*ben的帖子

id 对/元组的 HQL 查询

我正在尝试使用 HQL 查询两个域之间新创建的关系。

所以我想做类似的事情:

         select x.id, y.id
         from Author as x
          join x.books as y
         where (x.id, y.id) not in ((1,2),(3,4))
Run Code Online (Sandbox Code Playgroud)

或者

         select x.id, y.id
         from Author as x
          join x.books as y
         where (x.id, y.id) not in (:existingTuples)
Run Code Online (Sandbox Code Playgroud)

所以 existingTuples 是我已经知道的相关 ID。我想看看,已经建立了哪些关系。我知道可以使用 SQL 来实现,但是使用 HQL 我不必关心,如果它是 1-1、1-n 或 nm。

如果我直接在 HQL 中输入 ID,则会出现此错误:

org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: {vector}
Run Code Online (Sandbox Code Playgroud)

如果我提供

用于 :existingTuples 的字符串,例如 '(1,2),(3,4)',或

一个 org.apache.commons.lang3.tuple.Pair 列表,如 [new ImmutablePair(1L,2L), ..],或

像 [[1,2],[3,4]] 这样的列表列表

I get this error

org.hibernate.util.JDBCExceptionReporter.logExceptions([...]) at Line …
Run Code Online (Sandbox Code Playgroud)

hibernate hql

5
推荐指数
0
解决办法
1082
查看次数

标签 统计

hibernate ×1

hql ×1