title: Spring Data JPA findAllBy ... in ... orderBy input list
body: <p>I'm using JPA with Spring Boot in Kotlin/Java. I'm trying to find the proper and efficient way to do findBy ... In OrderBy input.</p>
  
  <p>I got a list of the Ids I want to find  and I want an ordered output with the same order. This is what JPA allows you:</p>
  
  <pre><code>@Repository
  interface PhotoRepository : JpaRepository&lt;Photo, String&gt;{
      // Which is the same as this query
      @Query("SELECT p FROM Photo p where p.id in :var1")
      fun findAllByIdIn(var1: List&lt;String&gt;, pageable: Pageable): List&lt;Photo&gt;
  }
  </code></pre>
  
  <p>Would be great if JPA allows you to do something like this:</p>
  
  <pre><code>@Repository
  interface PhotoRepository : JpaRepository&lt;Photo, String&gt;{
      @Query("SELECT p FROM Photo p where p.id in :var1 order by :var1")
      fun findAllByIdInOrderByvar1(var1: List&lt;String&gt;, pageable: Pageable): List&lt;Photo&gt;
  }
  </code></pre>
  
  <p>The size of the id list is between 500- 1500 items. There are lots of records in the database and the idea of select all the records is not feasible</p>
  
  <p>The contemplated solution is to do a <code>findAllByIdIn</code> and then match the records with the ids in list, which I think is not the proper solution, there are extra operations. The idea of changing the database is also contemplated.</p>