我正在将一个项目迁移到Sping Boot 3(Hibernate 6)。下面的本机查询是可分页的(查询简化以重现问题):
` @Query(
value = """
select s.id as id, s.name as name, gp.points
from specialist s
left join (select q.specialist_id, listagg(q.points, ';') as points from qualification q group by q.specialist_id) gp on gp.specialist_id = s.id
where name like :name
"""
, nativeQuery = true)
Page<SpecialistOverview> overview(@Param("name") String name, Pageable pageable);`
Hibernate生成的SQL如下所示:
select s.id as id, s.name as name, gp.points
from specialist s
left join (select q.specialist_id, listagg(q.points, ' fetch first ? rows only;') as points
from qualification q
group by q.specialist_id) gp on gp.specialist_id = s.id
where name like ?
order by name asc
正如你所看到的,“fetch first?rows only”部分现在是listagg函数的分隔符文字的一部分。当执行此查询时,它将导致DataIntegrityViolationException抱怨参数不匹配(第二个?是文字的一部分)。
Sping Boot 3.0.4(Hibernate 6.1.7.Final)
使用Sping Boot 2.7.9(Hibernate 5.6.15.Final),一切都很好:
select s.id as id, s.name as name, gp.points
from specialist s
left join (select q.specialist_id, listagg(q.points, ';') as points
from qualification q
group by q.specialist_id) gp on gp.specialist_id = s.id
where name like ?
order by name asc
limit ?
在打开Hibernate问题之前,我会在这里询问。我希望工作生成的SQL代码(如在Hibernate 5.6.x下)。
1条答案
按热度按时间hzbexzde1#
我将此报告为Sping Boot JPA中的一个bug,现已修复。
有关详细信息,请参见https://github.com/spring-projects/spring-data-jpa/issues/2884和https://github.com/spring-projects/spring-data-jpa/pull/2891。