@Transactional
  public void create(HostConfigMapping hostConfigMapping) {

    populateCache();

    // create in db
    entityManagerProvider.get().persist(buildHostConfigMappingEntity(hostConfigMapping));

    // create in cache
    Set<HostConfigMapping> set = hostConfigMappingByHost.get(hostConfigMapping.getHostName());
    if (set == null) {
      set = new HashSet<HostConfigMapping>();
      hostConfigMappingByHost.put(hostConfigMapping.getHostName(), set);
    }

    set.add(hostConfigMapping);
  }
  @Transactional
  public HostConfigMapping merge(HostConfigMapping hostConfigMapping) {

    populateCache();

    Set<HostConfigMapping> set = hostConfigMappingByHost.get(hostConfigMapping.getHostName());
    if (set == null) {
      set = new HashSet<HostConfigMapping>();
      hostConfigMappingByHost.put(hostConfigMapping.getHostName(), set);
    }

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

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

    return hostConfigMapping;
  }
  public HostConfigMappingEntity buildHostConfigMappingEntity(HostConfigMapping hostConfigMapping) {

    HostConfigMappingEntity hostConfigMappingEntity = new HostConfigMappingEntity();

    hostConfigMappingEntity.setClusterId(hostConfigMapping.getClusterId());
    hostConfigMappingEntity.setCreateTimestamp(hostConfigMapping.getCreateTimestamp());
    hostConfigMappingEntity.setHostName(hostConfigMapping.getHostName());
    hostConfigMappingEntity.setSelected(hostConfigMapping.getSelected());
    hostConfigMappingEntity.setServiceName(hostConfigMapping.getServiceName());
    hostConfigMappingEntity.setType(hostConfigMapping.getType());
    hostConfigMappingEntity.setUser(hostConfigMapping.getUser());
    hostConfigMappingEntity.setVersion(hostConfigMapping.getVersion());

    return hostConfigMappingEntity;
  }