title: Spring Data JPA. How to get only a list of IDs from findAll() method
body: <p>I have a very complicated model. Entity has a lot relationship and so on. </p>
  
  <p>I try to use Spring Data JPA and I prepared a repository. </p>
  
  <p>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:</p>
  
  <pre><code>@Query(value = "select id, name from Customer ")
  List&lt;Object[]&gt; myFindCustomerIds();
  </code></pre>
  
  <p>I didn't have any problems with performance. </p>
  
  <p>But when I invoke </p>
  
  <pre><code>List&lt;Customer&gt; findAll(); 
  </code></pre>
  
  <p>I had a big problem with performance. </p>
  
  <p>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. </p>
  
  <p>How to write a method to finding all customers with specifications for Customer entity but which returns only an IDs.</p>
  
  <p>like this:</p>
  
  <pre><code>List&lt;Long&gt; findAll(Specification&lt;Customer&gt; spec);
  </code></pre>
  
  <ul>
  <li>I cannot use in this case pagination.</li>
  </ul>
  
  <p>Please help. </p>