Skip to content

Commit d131c95

Browse files
schauderodrotbohm
authored andcommitted
DATAJPA-1241 - Removed dynamic check for getResultStream() on JPA query implementation classes.
We removed the dynamic, one-time lookup of a getResultStream() method on a JPA Query implementation which was basically introduced to accommodate the fact, that Hibernate 5.2's implementation already ships the method, but doesn't actually implement JPA 2.2. However, in varying circumstances, Hibernate returns a JPA Query proxy for the call to EntityManager.getQuery(…). If that's the case we can't implement the detected implementation method on that instance. Even worse, depending on which of the two we see first (Hibernate's implementation class or the JPA Query proxy) the optimization might not even kick in as the detection of the method is a one-time effort. Original pull request: #241.
1 parent d624296 commit d131c95

File tree

1 file changed

+0
-21
lines changed

1 file changed

+0
-21
lines changed

src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java

-21
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ static class StreamExecution extends JpaQueryExecution {
346346
private static final String NO_SURROUNDING_TRANSACTION = "You're trying to execute a streaming query method without a surrounding transaction that keeps the connection open so that the Stream can actually be consumed. Make sure the code consuming the stream uses @Transactional or any other way of declaring a (read-only) transaction.";
347347

348348
private static Method streamMethod = ReflectionUtils.findMethod(Query.class, "getResultStream");
349-
private static boolean dynamicCheck = streamMethod == null;
350349

351350
/*
352351
* (non-Javadoc)
@@ -366,27 +365,7 @@ protected Object doExecute(final AbstractJpaQuery query, Object[] values) {
366365
return ReflectionUtils.invokeMethod(streamMethod, jpaQuery);
367366
}
368367

369-
if (dynamicCheck) {
370-
371-
Method method = ReflectionUtils.findMethod(jpaQuery.getClass(), "getResultStream");
372-
373-
// Implementation available but on JPA 2.1
374-
if (method != null) {
375-
376-
// Cache for subsequent reuse to prevent repeated reflection lookups
377-
streamMethod = method;
378-
379-
return ReflectionUtils.invokeMethod(method, jpaQuery);
380-
381-
} else {
382-
383-
// Not available on implementation, skip further lookups
384-
dynamicCheck = false;
385-
}
386-
}
387-
388368
// Fall back to legacy stream execution
389-
390369
PersistenceProvider persistenceProvider = PersistenceProvider.fromEntityManager(query.getEntityManager());
391370
CloseableIterator<Object> iter = persistenceProvider.executeQueryWithResultStream(jpaQuery);
392371

0 commit comments

Comments
 (0)