SELECT puller
FROM Puller puller
WHERE puller.pullerUID
IN
(
( SELECT map.pullerUID
FROM PullerZipModelAndEndUseCategory map
WHERE map.endUseId
IN
( SELECT cat.id
FROM EndUse cat
WHERE cat.description = 'Mens Wear' OR cat.description = 'childrens wear' ) )
INTERSECT
( SELECT pullerFinish.pullerUID
FROM PullerFinishDetails pullerFinish
WHERE pullerFinish.zipTypeId
IN
(SELECT zip.id
FROM ZipType zip
WHERE zip.description = 'Metal' OR zip.description = 'Plastic' ))
)
我尝试使用AND子句拦截两个查询来从主表中获取数据 因为HQl不支持INTERSECT子句。我得到一个例外:
Dec 03, 2014 7:48:21 PM org.hibernate.hql.internal.ast.ErrorCounter reportError
ERROR: <AST>:1:461: unexpected AST node: AND
Dec 03, 2014 7:48:21 PM org.hibernate.hql.internal.ast.ErrorCounter reportError
ERROR: <AST>:1:461: unexpected AST node: AND
<AST>:1:461: unexpected AST node: AND
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4606)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr (HqlSqlBaseWalker.java:4215)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2076)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:794)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:595)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)