Hibernate HQL查询id对/元组
我试图使用HQL查询两个域之间新创建的关系 所以我想做一些类似的事情:Hibernate HQL查询id对/元组,hibernate,hql,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)) 或 因此,现有元组是我已经知道的相关ID。我想看看,已经建立了哪些关系。 我知道用SQL可以做到这一点,但用HQL我不必在意,如果它是1-1、1-n或n-m 如果直接
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))
或
因此,现有元组是我已经知道的相关ID。我想看看,已经建立了哪些关系。
我知道用SQL可以做到这一点,但用HQL我不必在意,如果它是1-1、1-n或n-m
如果直接在HQL中键入ID,则会出现以下错误:
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: {vector}
如果我提供
字符串:现有元组,如“(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))中添加not,它就可以工作了
有人知道如何格式化HQL,或者我必须以何种形式提供idtuple,以便它们是行元素吗?
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 (?)