@Override
  protected void mergeChildren(List<Wrapper<FilterType>> itemsToJoin) {
    List<Wrapper<FilterForm>> children = new ArrayList<Wrapper<FilterForm>>();

    String query = "from FilterForm f where f.filterTypeCode = ?";
    for (Wrapper<FilterType> wrapper : itemsToJoin) {
      if (wrapper.source().equals(Source.MANN.id())) {
        List<FilterForm> l = mannTemplate.find(query, wrapper.item().getCode());
        children.addAll(Wrapper.bySource(l, Source.MANN.id()));
      }
      if (wrapper.source().equals(Source.BASE.id())) {
        List<FilterForm> l = baseTemplate.find(query, wrapper.item().getCode());
        children.addAll(Wrapper.bySource(l, Source.BASE.id()));
      }
    }

    mergers.byClass(FilterForm.class).merge(children);
  }
  @Override
  public List<FilterType> merge(List<Wrapper<FilterType>> items) {
    Map<String /*businessKey*/, List<Wrapper<FilterType>>> keyMap =
        new HashMap<String, List<Wrapper<FilterType>>>();
    logger.trace("Merge for " + klass.getSimpleName());

    final List<FilterType> result = new ArrayList<FilterType>();

    // Groupping
    for (Wrapper<FilterType> item : items) {
      String businessKey = getBusinessKey(item);

      if (!keyMap.containsKey(businessKey)) {
        keyMap.put(businessKey, new ArrayList<Wrapper<FilterType>>());
      }

      keyMap.get(businessKey).add(item);
    }

    // Joining
    int counter = 0;
    for (Map.Entry<String, List<Wrapper<FilterType>>> item : keyMap.entrySet()) {
      counter++;
      if (counter % 100 == 0)
        logger.debug("Processing " + klass + " " + counter + " of " + keyMap.size());

      String businessKey = item.getKey();
      List<Wrapper<FilterType>> itemsToJoin = item.getValue();

      FilterType newItem = join(itemsToJoin);
      finalTemplate.save(newItem);
      for (Wrapper<FilterType> itemToJoin : itemsToJoin) {
        addToContext(itemToJoin.source(), itemToJoin.item().getCode(), newItem.getCode());
      }

      mergeChildren(itemsToJoin);
      result.add(newItem);
    }

    return result;
  }