2

我有如下查询。但是当它执行时我收到错误消息意外令牌:除了

select d from DimensionStone d inner join d.stockRegister s 
where d.stockRegister.stockRegisterId <=? and s.application.applicationId=? 
and d.isIssued='No' or (s.stockRegisterId <=? and d.isIssued='Yes' 
and d.issuedDate>(select max(updatedOn) from StockRegister st 
where st.stockRegisterId<? and st.application.applicationId=?)) 
except (select d1 from DimensionStone d1 inner join d1.stockRegister s1 
where s1.stockRegisterId <=? and s1.application.applicationId=? and 
d1.isIssued='No')

我该如何解决这个问题。我已经通过谷歌搜索了足够多的内容。但是我找不到想要的答案。请帮助我

4

3 回答 3

0

替换为不存在的除外:

select d from DimensionStone d inner join d.stockRegister s 
where d.stockRegister.stockRegisterId <=? and s.application.applicationId=? 
and d.isIssued='No' or (s.stockRegisterId <=? and d.isIssued='Yes' 
and d.issuedDate>
    (select max(updatedOn) from StockRegister st 
    where st.stockRegisterId<? and st.application.applicationId=?)) 
and not exists
    (select 'next' from DimensionStone d1 inner join d1.stockRegister s1 
    where s1.stockRegisterId <=? and s1.application.applicationId=? and 
    d1.isIssued='No')
于 2013-08-27T12:13:43.770 回答
0

关键字 EXCEPT 似乎没有被 HQL 处理(两者都没有),我得到了和你一样的例外。
我实现了使用关键字重现异常查询的行为:NOT IN (NOT EXISTS 也可以工作)
示例:

SELECT a FROM MyTable a WHERE a NOT IN (SELECT a FROM MyTable a, otherTable l WHERE l.id = ?1 AND l.myObject.id = a.id)
于 2015-01-07T09:44:11.487 回答
0

except不是有效的 HQL 关键字;如果您想使用特定的 RDBMS 语法 Session.createSQLQuery(String sql),请使用 aResultTransformer将每个记录集行映射到对象DimensionStone

于 2013-08-27T11:03:06.710 回答