2

by default JPA entities are order by id. Can we expect the result list in the order of input given to IN Clause?

example

List<Long> ids=  new ArrayList<Long>();
    ids.add(1004L);
    ids.add(1003L);
    ids.add(1001L);
    ids.add(1002L);


    Query query = entityManager.createQuery("select p from Person p where p.id in (:pids)");
    query.setParameter("pids" , ids);
    List<Person> personsList= query.getResultList();

The personsList i get above is ordered by person ID, but i need the result list the order i provided(1004L,1003L,1001L,1002L)

Is that possible?

Note : Person not implemented compareTo()

user2555212
  • 165
  • 1
  • 14

0 Answers0