我在 Hibernate 中使用 JPA,我今天看到了一个奇怪的行为。
以下查询工作正常:
select x.fichaCaracterizacao.id
from FichaParecer x
where x.departamento in :departamentos
但是,如果我在内部查询中使用它,则会引发异常,如下所示:
select p.fichaCaracterizacao.id
from FichaParecer p
where 1=1 and
p.id in (select x.fichaCaracterizacao.id
from FichaParecer x
where x.departamento in :departamentos)
它抛出以下异常:
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: , near line 1, column 244 [select p.fichaCaracterizacao.id from br.ufscar.siga.cadastrosgerais.entity.FichaParecer p where 1=1 and p.id in (select x.fichaCaracterizacao.id from br.ufscar.siga.cadastrosgerais.entity.FichaParecer x where x.departamento in :departamentos0_, :departamentos1_, :departamentos2_)]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1348) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:261) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
这只发生在“departamentos”集合有多个项目时。
Hibernate 支持这个吗?还是我做错了什么?
编辑:我正在使用 Hibernate 4.0.1.Final