I'm using Spring data JPA. I have a situation where my database identity is a surrogate key which returns three records, but I have implemented the equals method to reduce the collection down to two names. How to update the Page<Person> byName after filtering out / removing records from it at the service layer?
Example:
ID license Name
1 123456 Kim Kardashian
2 123456 Kim Kardashian West
3 123456 Kim Kardashian
When searching I want to return two records. I have overridden the equals and hashcode method to define equality based on the, license and name attributes. I'm okay with it arbitrarily picking 1 or 3 to represent the 123456 Kim Kardashian record.
ID license Name
1 123456 Kim Kardashian
2 123456 Kim Kardashian West
Code snippet of the repository returning the 3 records, and now at the service layer I would like to filter it down to the two records.
Page<Person> byName = PersonRepository.findByName(
name,
pageable);
//Now remove duplicates based on the equals() method rather than database identity (this is a read-only entity.
List<Person> collect = byName.get().distinct().collect(Collectors.toList());
//how to place the replace the list back in the byName and the paging information is accurate?
return ????;