From 8a95dba706ec3c482f61d2bb5f8b44dacc4b2c61 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 99bf03c43..659c04c7d 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 @@ -130,7 +130,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)); @@ -144,16 +144,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