I am using JPA and I have a list object containing all PKs of the objects I required to retrieve from database. What is the best approach to use this list in order to acquire the objects themselves?
If you think most of the objects are already in the JPA cache, then just use find().
Otherwise, using an IN query with the list of Ids is probably the most efficient (assuming singleton Id anyway).
If the list of Ids is very large, then you may need to split it up into batches of 200.
Thank you for posting reply.
Can you please explain more about using IN? should I create a JPQL dynamically and include all PK form the list into the dynamically created query or I can pass the list to JPQL directly?