Skip to content

Commit 226e898

Browse files
committed
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
1 parent 8580da4 commit 226e898

File tree

1 file changed

+5
-10
lines changed
  • spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query

1 file changed

+5
-10
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static boolean hasNamedQuery(EntityManager em, String queryName) {
132132
@Nullable
133133
public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em) {
134134

135-
final String queryName = method.getNamedQueryName();
135+
String queryName = method.getNamedQueryName();
136136

137137
if (LOG.isDebugEnabled()) {
138138
LOG.debug(String.format("Looking up named query %s", queryName));
@@ -146,16 +146,11 @@ public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em
146146
throw QueryCreationException.create(method, "Scroll queries are not supported using String-based queries");
147147
}
148148

149-
try {
150-
151-
RepositoryQuery query = new NamedQuery(method, em);
152-
if (LOG.isDebugEnabled()) {
153-
LOG.debug(String.format("Found named query %s", queryName));
154-
}
155-
return query;
156-
} catch (IllegalArgumentException e) {
157-
return null;
149+
RepositoryQuery query = new NamedQuery(method, em);
150+
if (LOG.isDebugEnabled()) {
151+
LOG.debug(String.format("Found named query %s", queryName));
158152
}
153+
return query;
159154
}
160155

161156
@Override

0 commit comments

Comments
 (0)