'Fetching and Paging in the same time with FetchableFluentQuery and QuerydslPredicateExecutor

Spring-data-JPA has a new feature FetchableFluentQuery but seemingly not yet documented (in 2.6.3 at least or I haven't found it, so correct me if I am wrong) I've been waiting for this feature a long while. We are now able to fetch associations (ManyToOne or ManyToMany) when using QueryDsl executor.

So in the following example we could select Task entities according to some QueryDsl Predicate and fetch the ManyToOne "manager" entity:

    Iterable<Task> iterable = taskRepository.findBy(predicate,
            ffq -> ffq.project("manager").all());

This FetchableFluentQuery also manages Pageable so we could use:

    Page<Task> page = taskRepository.findBy(predicate,
            ffq -> ffq.page(_pageable)); 

Unfortunately I haven't been able to find the right syntax to use both fetching and pagination, and trying the following does not work because the manager(s) are not fetched.

    Page<Task> page = taskRepository.findBy(predicate,
            ffq -> ffq.project("manager").page(_pageable)); 

If you have the right syntax, I would appreciate.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source