### Question:
HostVersionDAO extends CrudDAO<HostVersionEntity, Long> { @Override @Transactional public void create(HostVersionEntity entity) throws IllegalArgumentException{ if (entity.getRepositoryVersion() == null) { throw new IllegalArgumentException("RepositoryVersion argument is not set for the entity"); } super.create(entity); entity.getRepositoryVersion().updateHostVersionEntityRelation(entity); } HostVersionDAO(); @Override @Transactional void create(HostVersionEntity entity); @RequiresSession List<HostVersionEntity> findByClusterStackAndVersion(
      String clusterName, StackId stackId, String version); @RequiresSession List<HostVersionEntity> findByHost(String hostName); @RequiresSession List<HostVersionEntity> findByClusterAndHost(String  clusterName, String hostName); @RequiresSession List<HostVersionEntity> findByCluster(String  clusterName); @RequiresSession List<HostVersionEntity> findByClusterAndState(String clusterName, RepositoryVersionState state); @RequiresSession List<HostVersionEntity> findByClusterHostAndState(String  clusterName, String hostName, RepositoryVersionState state); @RequiresSession HostVersionEntity findByClusterStackVersionAndHost(String clusterName,
      StackId stackId, String version, String hostName); @RequiresSession List<HostVersionEntity> findHostVersionByClusterAndRepository(long clusterId,
      RepositoryVersionEntity repositoryVersion); @RequiresSession List<HostVersionEntity> findByRepositoryAndStates(RepositoryVersionEntity repositoryVersion,
      Collection<RepositoryVersionState> states); @RequiresSession HostVersionEntity findHostVersionByHostAndRepository(HostEntity host,
      RepositoryVersionEntity repositoryVersion); @Transactional void removeByHostName(String hostName);  }### Answer:
@Test public void testDuplicates() throws Exception { HostEntity host1 = hostDAO.findByName("test_host1"); RepositoryVersionEntity repoVersion = helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2200); HostVersionEntity hostVersionEntity1 = new HostVersionEntity(host1, repoVersion, RepositoryVersionState.CURRENT); try { hostVersionDAO.create(hostVersionEntity1); Assert.fail("Each host can have a relationship to a repo version, but cannot have more than one for the same repo"); } catch (Exception e) { } }