使用hibernate 4.3.11.final。
我们使用@Query annotation发出请求,我们在子选择查询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子句是正确生成的(添加了左括号)但是subselect中的那个不是。
生成的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'修复了最近的hibernate版本?我查看了hibernate问题,但我无法找到有关此行为的任何信息。
最好的问候。
答案 0 :(得分:0)
也许这是一个错误,但它不会在4.3中修复。
您需要在5.2上使用测试用例复制它并打开Jira问题。
答案 1 :(得分:0)
这是一个错误,它已经通过hibernate 5.2进行了更正。