code: public List<T> getDomainObjectsAsList(Set<? extends KEY> keys) {
          // it is not "possible" to use huge number of parameters in a
          // Restrictions.in criterion and therefore we chunk the query
          // into pieces
          List<T> all = new ArrayList<T>();
          Iterator<? extends KEY> iter = keys.iterator();
          List<KEY> chunkKeys = new ArrayList<KEY>();
          for (int i = 1; iter.hasNext(); i++) {
              KEY element = iter.next();
              chunkKeys.add(element);
              if ((i % CHUNK_SIZE) == 0) {
                  all.addAll(getChunk(chunkKeys));
                  chunkKeys = new ArrayList<KEY>();
              }
          }
          // and then the last part
          if (!chunkKeys.isEmpty()) {
              all.addAll(getChunk(chunkKeys));
          }
  
          return all;
      }
docs: Fetch existing domain objects based on natural keys
  
  @param keys
  Set of natural keys for the domain objects to fetch
  @param resultAsSet
  indicates if the keys are unique or not, eg. the resulting map
  must be a set of objects.
  @return Map with keys and domain objects