@RequiresSession
  public List<HostEntity> findByStage(StageEntity stageEntity) {
    TypedQuery<HostEntity> query = entityManagerProvider.get().createQuery(
        "SELECT host FROM HostEntity host " +
            "WHERE host.hostName IN (" +
            "SELECT DISTINCT host.hostName " +
            "FROM HostEntity host " +
            "JOIN host.hostRoleCommandEntities command " +
            "JOIN command.stage stage " +
            "WHERE stage=:stageEntity)", HostEntity.class);
    query.setParameter("stageEntity", stageEntity);
    try {
      return query.getResultList();
    } catch (NoResultException e) {
      return Collections.emptyList();
    }
  }
Looks for Host by ID
@param hostId ID of Host
@return Found entity or NULL
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java