From 226e8986904de744c092adcb7e254564e8badc4a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 1 Aug 2024 10:17:03 +0200 Subject: [PATCH] Remove exception guard for absent query handling. We now no longer fall back to an absent query when a NamedQuery construction fails with IllegalArgumentException. IllegalArgumentException is also used by the JPA API to indicate an absent query. In other cases, where we fail with IllegalArgumentException, we fell back to query derivation as handling IAE as signal for an absent query. We already have better query absence checks in place so we can remove the try/catch blocks in favor of the named query presence check. Closes #3550 --- .../data/jpa/repository/query/NamedQuery.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java index ea85d518d..c0fa06618 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java @@ -132,7 +132,7 @@ final class NamedQuery extends AbstractJpaQuery { @Nullable public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em) { - final String queryName = method.getNamedQueryName(); + String queryName = method.getNamedQueryName(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Looking up named query %s", queryName)); @@ -146,16 +146,11 @@ final class NamedQuery extends AbstractJpaQuery { throw QueryCreationException.create(method, "Scroll queries are not supported using String-based queries"); } - try { - - RepositoryQuery query = new NamedQuery(method, em); - if (LOG.isDebugEnabled()) { - LOG.debug(String.format("Found named query %s", queryName)); - } - return query; - } catch (IllegalArgumentException e) { - return null; + RepositoryQuery query = new NamedQuery(method, em); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Found named query %s", queryName)); } + return query; } @Override