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.
This commit is contained in:
Jens Schauder
2018-01-05 09:16:27 +01:00
committed by Oliver Gierke
parent c389f467cc
commit 15d3aa1105

View File

@@ -346,7 +346,6 @@ public abstract class JpaQueryExecution {
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.";
private static Method streamMethod = ReflectionUtils.findMethod(Query.class, "getResultStream");
private static boolean dynamicCheck = streamMethod == null;
/*
* (non-Javadoc)
@@ -366,27 +365,7 @@ public abstract class JpaQueryExecution {
return ReflectionUtils.invokeMethod(streamMethod, jpaQuery);
}
if (dynamicCheck) {
Method method = ReflectionUtils.findMethod(jpaQuery.getClass(), "getResultStream");
// Implementation available but on JPA 2.1
if (method != null) {
// Cache for subsequent reuse to prevent repeated reflection lookups
streamMethod = method;
return ReflectionUtils.invokeMethod(method, jpaQuery);
} else {
// Not available on implementation, skip further lookups
dynamicCheck = false;
}
}
// Fall back to legacy stream execution
PersistenceProvider persistenceProvider = PersistenceProvider.fromEntityManager(query.getEntityManager());
CloseableIterator<Object> iter = persistenceProvider.executeQueryWithResultStream(jpaQuery);