Hibernate:在子 select 查询中使用 IN 子句时出现错误
Hibernate : stange error when using the IN clause in sub select query
使用休眠 4.3.11.final.
我们使用@Query 注释发出请求,我们在子select 查询ex 中使用in 子句:
select distinct doc from DocumentType doc join doc.usages u where u.institute not in :institutes and doc.id not in (select distinct doc1.id from DocumentType doc1 join doc1.usages u1 where u1.institute in :institutes)
第一个 in 子句已正确生成(添加了括号),但子句中的第一个 select 不是。
生成的 sql 是:
select distinct doc from fr.itce.pen.model.customer.folder.DocumentType doc join doc.usages u where u.institute not in (:institutes_0_, :institutes_1_) and doc.id not in (select distinct doc1.id from fr.itce.pen.model.customer.folder.DocumentType doc1 join doc1.usages u1 where u1.institute in :institutes_0_, :institutes_1_)]
解决方法是在声明的查询中用括号将部分括起来,如:
select distinct doc from DocumentType doc join doc.usages u where u.institute not in :institutes and doc.id not in (select distinct doc1.id from DocumentType doc1 join doc1.usages u1 where u1.institute in (:institutes))
有没有更好的方法让它工作,和/或这个 'bug' 在最近的休眠版本中是否已修复?我查看了休眠问题,但找不到有关此行为的任何信息。
此致。
可能是个bug,4.3不会修复。
您需要使用测试用例在 5.2 上复制它并打开 Jira 问题。
这是一个错误,已在 hibernate 5.2 中得到纠正。
使用休眠 4.3.11.final.
我们使用@Query 注释发出请求,我们在子select 查询ex 中使用in 子句:
select distinct doc from DocumentType doc join doc.usages u where u.institute not in :institutes and doc.id not in (select distinct doc1.id from DocumentType doc1 join doc1.usages u1 where u1.institute in :institutes)
第一个 in 子句已正确生成(添加了括号),但子句中的第一个 select 不是。
生成的 sql 是:
select distinct doc from fr.itce.pen.model.customer.folder.DocumentType doc join doc.usages u where u.institute not in (:institutes_0_, :institutes_1_) and doc.id not in (select distinct doc1.id from fr.itce.pen.model.customer.folder.DocumentType doc1 join doc1.usages u1 where u1.institute in :institutes_0_, :institutes_1_)]
解决方法是在声明的查询中用括号将部分括起来,如:
select distinct doc from DocumentType doc join doc.usages u where u.institute not in :institutes and doc.id not in (select distinct doc1.id from DocumentType doc1 join doc1.usages u1 where u1.institute in (:institutes))
有没有更好的方法让它工作,和/或这个 'bug' 在最近的休眠版本中是否已修复?我查看了休眠问题,但找不到有关此行为的任何信息。
此致。
可能是个bug,4.3不会修复。
您需要使用测试用例在 5.2 上复制它并打开 Jira 问题。
这是一个错误,已在 hibernate 5.2 中得到纠正。