public HostVersionEntity createHostVersion(String hostName, RepositoryVersionEntity repositoryVersionEntity,
      RepositoryVersionState repositoryVersionState) {
    HostEntity hostEntity = hostDAO.findByName(hostName);
    HostVersionEntity hostVersionEntity = new HostVersionEntity(hostEntity, repositoryVersionEntity, repositoryVersionState);
    hostVersionEntity.setHostId(hostEntity.getHostId());
    hostVersionDAO.create(hostVersionEntity);

    hostEntity.getHostVersionEntities().add(hostVersionEntity);
    hostDAO.merge(hostEntity);

    return hostVersionEntity;
  }
Convenient method to create host version for given stack.
ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java