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.
In the Spring Data shipped with Spring Boot 2.7.0 an
order byclause alias is detected incorrectly. It seems like thedetectAliasmethod inQueryUtilsclass is being confused by subquery in thewhereclause of the following query: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 bynumberSpring Data generatesorder by vehicle.number ascclause.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.