querydsl union multiple queries in one

eclipselink, jpa, querydsl

Solution

I'm asking if it is possible to use queryDSL to basically make 3 separate queries and union them together so that I can use paging on the unioned list.

No, that's not possible with Querydsl. You can write the query in such a way that it will return Employee instances that match at least one of the constraints, but the result will be a single Employee list.

Problem

Lets say I have a class like this: ``` @Entity public class Employee{ private Long Id; private String jobTitle; private String firstName; ... getters and setters } ``` Is it possible to do single query and return multiple sets of data? Say I have a method signature in my repository that looks like this: ``` public EmployeeQueryResult getEmployeeQuery(Long currentUserId, String jobTitle, List<String> names); ``` and I want to use this method to get the current employee by id, all employees that have a specific job title, and all employees that have a name: ``` public class EmployeeQueryResults{ private Employee currentEmployee; private List<Employee> employeesWithJobTitle; private List<Employee> employeesWithName; ... } ``` I'm asking if it is possible to use queryDSL to basically make 3 separate queries and union them together so that I can use paging on the unioned list.

Original source

Related problems