@Override
    public SamlIdPMetadataDocument fetchInternal(final Optional<SamlRegisteredService> registeredService) {
        try {
            if (registeredService.isPresent()) {
                val query = buildQuery(registeredService);
                val results = query.getResultList();
                if (!results.isEmpty()) {
                    return results.getFirst();
                }
            }
            return buildQuery(Optional.empty()).getSingleResult();
        } catch (final NoResultException e) {
            LOGGER.debug(e.getMessage(), e);
        }
        return new SamlIdPMetadataDocument();
    }
This is {@link JpaSamlIdPMetadataLocator}.

@author Misagh Moayyed
@since 6.0.0
support/cas-server-support-saml-idp-metadata-jpa/src/main/java/org/apereo/cas/support/saml/idp/metadata/JpaSamlIdPMetadataLocator.java