id对/元组的HQL查询

时间:2013-11-04 16:15:15

标签: hibernate 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))

         select x.id, y.id
         from Author as x
          join x.books as y
         where (x.id, y.id) not in (:existingTuples)

所以现有的元组是我已经知道的相关ID。我希望看到,已经建立了哪些关系。 我知道可以用SQL做到这一点,但是对于HQL我不必关心,如果它是1-1,1-n或n-m。

如果我直接在HQL中输入ID,我会收到此错误:

org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: {vector}

如果我提供

一个字符串for:existingTuples,如'(1,2),(3,4)'或

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

像[[1,2],[3,4]]

这样的列表

我收到此错误

org.hibernate.util.JDBCExceptionReporter.logExceptions([...]) at Line 234
ERROR: arguments of row IN must all be row expressions

我还检查了spylog,查询永远不会被执行,生成的SQL看起来像这样:

select author0_.id as col_0_0_, books1_.id as col_1_0_ 
 from author author0_ 
  inner join book books1_ on author0_.id=books1_.author_id 
 where (author0_.id , books1_.id) not in  (?)

如果我接受这个查询并且只是添加((1,2),(3,4))它就可以了。

任何人都知道如何格式化HQL,或者我必须以哪种形式提供idTuples,以便它们是行元素?

0 个答案:

没有答案
相关问题