@Override protected List<Rule> findByIDs(final List<Long> subList) { // values retrieved in bulk from the database final List<Rule> retrivedFronDb = ruleService.findByUids(subList); // we have to order the values based on the values in subList, due to the promotion dependency // which needs to have the dependent object after the non-depend ones final Comparator<Rule> comparator = new Comparator<Rule>() { @Override public int compare(final Rule rule1, final Rule rule2) { Integer postion1 = subList.indexOf(rule1.getUidPk()); Integer position2 = subList.indexOf(rule2.getUidPk()); return postion1.compareTo(position2); } }; Collections.sort(retrivedFronDb, comparator); return retrivedFronDb; }