@RequiresSession
  public ServiceConfigEntity findMaxVersion(Long clusterId, String serviceName) {
    TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createQuery("SELECT scv FROM ServiceConfigEntity scv " +
      "WHERE scv.clusterId=?1 AND scv.serviceName=?2 AND scv.version = (" +
      "SELECT max(scv2.version) FROM ServiceConfigEntity scv2 " +
      "WHERE scv2.clusterId=?1 AND scv2.serviceName=?2)", ServiceConfigEntity.class);

    return daoUtils.selectSingle(query, clusterId, serviceName);
  }
Gets the latest service configurations for the specified cluster and stack.

@param clusterId
         the cluster (not {@code null}).
@param stackId
         the stack (not {@code null}).
@return the latest service configurations for the cluster and stack.
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java