Skip to content

Accept additional function argument literals for correct native query with pageable rewrite #2884

Closed
@futzlig

Description

@futzlig

I'm migrating a project from Spring Boot 2.7.9 to 3.0.4. I have the following pageable, native query with a list_agg function:

    @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);

Calling this function results under Spring Boot 3.0.x in a DataIntegrityViolationException because the second parameter could not be bound. This ist the generated 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 ?

As you can see the "fetch first ? rows only" section is now part of the delimter literal of the list_agg function.

Under Spring Boot 2.7.9 everything works as expected.

Attached projects to reproduce this anomality.

Hibernate6NativeQueryIssue.zip
PageableNativeQuerySpringBoot2.zip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions