Reusing a query by reinitializing a parameter (which contains a collection of values) returns a wrong result. The number of elements is correct in the result but the result is not deterministic. The second execution contains elements of the first result. E.g.
- query.setParameter("id", Arrays.asList("1", "2", "3"); query.getResultList(); // returns 1, 2, 3
- query.setParameter("id", Arrays.asList("4", "5", "6"); query.getResultList(); // reusing the same query doesn't return 4, 5, 6 but a random result with 3 objects, e.g. 1, 4, 6
Sample code attached. |