Hi,
I am facing a problem where I need to order the paging result in a more complex way than Sort can handle.
I have a situation that reminds a lot of a parent child one where the parent is null when it is the top-level.
The result must be delivered in a list with parents and children ordered likeCode:class Entity { Entity parent; List<Entity> children; ... }
Description Id ParentId 1 1 NULL 1.1 2 1 1.2 3 1 2 4 NULL 2.1 5 4 2.2 6 4 3 7 NULL 4 8 NULL 4.1 9 8
The easiest way writing SQL when just handling just two levels are:
SELECT *
FROM Table
LEFT JOIN Table Parent
ON Table.ParentId = Parent.Id
ORDER BY
COALESCE(Parent.Description, Temp.Description),
CASE WHEN Table.ParentId IS NULL THEN 0 ELSE 1 END,
Table.Description
Now when I am using Spring-data with querydsl I have to ask if this is possible. The reason why I want to use Spring-Data in my query with query-dsl is because the where-clause is complex and that spring-data is offering good support for paging. I found the QueryDslPredicateExecutor but it does not support sorting with OrderSpecifier when using paging.
Am I looking for something that are not implemented or something that is impossible?


Reply With Quote
