class DBUtil {

    public static Criterion getBoundedInCriterion(String propertyName, Collection idCollection) {
        Disjunction disjunction = Restrictions.disjunction();
        List idList;
        int fromIndex = 0;

        // apply no restriction - empty conjunction is always true
        if(CollectionUtils.isEmpty(idCollection)) {
            return Restrictions.conjunction();
        }

        if (idCollection instanceof List) {
            idList = (List)idCollection;
        } else {
            idList = (List)idCollection.parallelStream().collect(Collectors.toList());
        }

        while (maxInElements > 0 && fromIndex < idList.size()) {
            int toIndex = Math.min(fromIndex + maxInElements, idList.size());
            List idSubList = idList.subList(fromIndex, toIndex);
            disjunction.add(Restrictions.in(propertyName, idSubList));
            fromIndex += maxInElements;
        }

        return disjunction;
    }

}