@RequiresSession
  public ServiceConfigEntity getLastServiceConfig(Long clusterId, String serviceName) {
    TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().
        createQuery("SELECT scv FROM ServiceConfigEntity scv " +
          "WHERE scv.clusterId = ?1 AND scv.serviceName = ?2 " +
          "ORDER BY scv.createTimestamp DESC",
          ServiceConfigEntity.class);

    return daoUtils.selectOne(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