我有如下查询。但是当它被执行时,我收到错误消息意外令牌:
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')
我如何才能解决这个问题。我已经通过google搜索了足够的内容。但是我找不到想要的答案。请帮帮我
答案 0 :(得分:0)
except
不是有效的HQL关键字;如果要使用特定的RDBMS语法
Session.createSQLQuery(String sql)
和ResultTransformer
将每个记录集行映射到对象DimensionStone
答案 1 :(得分: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')
答案 2 :(得分:0)
关键字EXCEPT似乎不是由HQL处理的(既不是MINUS),我也得到了与你相同的例外。
我实现了使用关键字重现except查询的行为: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)