Skip to content

Commit 398b82b

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 7b2ae0e commit 398b82b

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
@@ -129,7 +129,7 @@ static boolean hasNamedQuery(EntityManager em, String queryName) {
129129
@Nullable
130130
public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em) {
131131

132-
final String queryName = method.getNamedQueryName();
132+
String queryName = method.getNamedQueryName();
133133

134134
if (LOG.isDebugEnabled()) {
135135
LOG.debug(String.format("Looking up named query %s", queryName));
@@ -143,16 +143,11 @@ public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em
143143
throw QueryCreationException.create(method, "Scroll queries are not supported using String-based queries");
144144
}
145145

146-
try {
147-
148-
RepositoryQuery query = new NamedQuery(method, em);
149-
if (LOG.isDebugEnabled()) {
150-
LOG.debug(String.format("Found named query %s", queryName));
151-
}
152-
return query;
153-
} catch (IllegalArgumentException e) {
154-
return null;
146+
RepositoryQuery query = new NamedQuery(method, em);
147+
if (LOG.isDebugEnabled()) {
148+
LOG.debug(String.format("Found named query %s", queryName));
155149
}
150+
return query;
156151
}
157152

158153
@Override

0 commit comments

Comments
 (0)