Skip to content

detectAlias() in QueryUtils incorreclty detects order by clause alias #2563

@agzamovr

Description

@agzamovr

In the Spring Data shipped with Spring Boot 2.7.0 an order by clause alias is detected incorrectly. It seems like the detectAlias method in QueryUtils class is being confused by subquery in the where clause of the following query:

    @Test
    void testQueryAlias() {
        String query = """
                SELECT o
                  FROM Order o
                   AND EXISTS(SELECT 1
                                FROM Vehicle vehicle
                               WHERE vehicle.vehicleOrderId = o.id
                                 AND LOWER(COALESCE(vehicle.make, '')) LIKE :query)
                """;
        String alias = QueryUtils.detectAlias(query);
        assertThat(alias).isEqualTo("vehicle");
    }

This is a simplified version of the real query but the issue is still reproduced with this one. When running this query with PageRequest.of(0, 20, Sort.by("number")) pageable object to sort orders by number Spring Data generates order by vehicle.number asc clause.

There is a similar issue that was fixed and released in Spring Data 2.7.0. However, it looks like the bug is still there.

Metadata

Metadata

Assignees

Labels

in: query-parserEverything related to parsing JPQL or SQL

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions