Is it possible to get pagable data from list of QueryByExample in JPA?

28 Views Asked by At

A table has multiple columns and ManyToOne relationshps to/from other tables.

To collect data, query needs to be done on multiple columns with multile values and it should be pageable.

QueryByExample works well for most of the values.

But the requirement is that 2 columns need to have multiple values.

e.g. -

Table Person {FirstName, LastName, MaritalStatus, Age, Gender}

Then the query,

Page<Person> = personRepository.findAll(Example.of(Person with single/no value in each column), PageRequest.of(0, 10))

works well.

Now, the requirement is to have List for FirstName and LastName.

e.g. -

List<String> firstNames = Arrays.asList("AName", "BName", "CName")
List<String> lastNames = Arrays.asList("xName", "yName", "zName")

How to query Person with Pagination?

1

There are 1 best solutions below

0
Ln.J On

Yes, it's possible:

  • Use native Query with pagination method
  • Use parameter for number of page and line >> sql pagination method