Hibernate生成无效代码?数据库不支持多列子查询

时间:2018-02-25 19:59:57

标签: hibernate orm h2

我使用的是Hibernate 5.2.9和H2数据库1.4.196(两者都是最新的或相当接近)。

我的一个条件查询正在生成此SQL:

select count(*) as col_0_0_ from ListingDetailBaseDto listingdet0_ 
where listingdet0_.ListPrice>=500000 
   and (listingdet0_.ListPrice<=5000000 or listingdet0_.AskPrcLow<=5000000) 
   and listingdet0_.TotBds>=0 and listingdet0_.FB>=0 
   and ((listingdet0_.address, listingdet0_.apn, listingdet0_.city, 
         listingdet0_.state, listingdet0_.zip) 
       in (select address1_.address, address1_.apn, address1_.city,
           address1_.state, address1_.zip from Address address1_ 
           where ? in (select boundaries2_.boundaries 
                       from Address_boundaries boundaries2_ 
                       where address1_.id=boundaries2_.Address_id) 
              or ? in (select boundaries3_.boundaries 
                       from Address_boundaries boundaries3_ 
                        where address1_.id=boundaries3_.Address_id)
           )) 
   and (listingdet0_.Status=? or listingdet0_.Status=?) 
   and listingdet0_.ctcValidTo>? 
   and listingdet0_.UpdtDate<=?

这就是错误Subquery is not a single column query。该错误被广泛记录,并且由于在H2中对多列表达式的一般缺失支持。另请参阅Where() in (select) H2

现在,我开始使用Hibernate的主要原因之一是将自己与数据库引擎的特性隔离开来。

如何告诉Hibernate多列表达式不是这个数据库的功能,并让它生成正确的SQL?例如,它可以使用JOIN而不是IN子查询。

Hibernate会生成无效代码吗?

0 个答案:

没有答案