Skip to content

Commit fae1a35

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 acccb76 commit fae1a35

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
@@ -342,7 +342,6 @@ static class StreamExecution extends JpaQueryExecution {
342342
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.";
343343

344344
private static Method streamMethod = ReflectionUtils.findMethod(Query.class, "getResultStream");
345-
private static boolean dynamicCheck = streamMethod == null;
346345

347346
/*
348347
* (non-Javadoc)
@@ -362,27 +361,7 @@ protected Object doExecute(final AbstractJpaQuery query, Object[] values) {
362361
return ReflectionUtils.invokeMethod(streamMethod, jpaQuery);
363362
}
364363

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

0 commit comments

Comments
 (0)