Spring Data JPA. How to get only a list of IDs from findAll() method
12:20 19 May 2015

I have a very complicated model. Entity has a lot relationship and so on.

I try to use Spring Data JPA and I prepared a repository.

but when I invoke a method findAll() with specification for the object a have a performance issue because objects are very big. I know that because when I invoke a method like this:

@Query(value = "select id, name from Customer ")
List myFindCustomerIds();

I didn't have any problems with performance.

But when I invoke

List findAll(); 

I had a big problem with performance.

The problem is that I need to invoke findAll method with Specifications for Customer that is why I cannot use method which returns a list of arrays of objects.

How do I write a method to find all customers with specifications for the Customer entity but which returns only IDs.

like this:

List findAll(Specification spec);
  • I cannot use in this case pagination.

Please help.

spring spring-data-jpa specifications criteria-api