class HostConfigMappingDAO {

  @Transactional
  public HostConfigMapping merge(HostConfigMapping hostConfigMapping) {
    populateCache();

    Long hostId = hostConfigMapping.getHostId();
    if (hostId != null) {
      Set<HostConfigMapping> set;
      if (hostConfigMappingByHost.containsKey(hostId)) {
        set = hostConfigMappingByHost.get(hostId);
      } else {
        set = new HashSet<>();
        hostConfigMappingByHost.put(hostId, set);
      }

      //Update object in set
      set.remove(hostConfigMapping);
      set.add(hostConfigMapping);

      entityManagerProvider.get().merge(buildHostConfigMappingEntity(hostConfigMapping));
    }

    return hostConfigMapping;
  }

}