HQL query for id pairs / tuples

故事扮演 提交于 2019-12-12 09:43:25

问题


I am trying to query for newly created relations between two domains using HQL.

So I want to do something similar to this:

         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))

or

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

So existingTuples are the related IDs that I already know. And I would like to see, which relations have been created. I know it's possible to do it with SQL, but with HQL I would not have to care about, if it's 1-1, 1-n or n-m.

If I am typing the IDs directly in the HQL i get this error:

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

If I am providing

a String for :existingTuples like '(1,2),(3,4)', or

a List of org.apache.commons.lang3.tuple.Pair like [new ImmutablePair(1L,2L), ..], or

a List of List like [[1,2],[3,4]]

I get this error

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

I also checked with spylog, the query does never get executed, the generated SQL looks like this:

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  (?)

If I take this query and just add not in ((1,2), (3,4)) it works.

Anyone has a clue how to format the HQL, or in which form I would have to provide the idTuples, so that they are row elements?

来源:https://stackoverflow.com/questions/19772032/hql-query-for-id-pairs-tuples

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!