From 15d3aa1105d82f9fdbb8d2f1d58c4cd212f4d968 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 5 Jan 2018 09:16:27 +0100 Subject: [PATCH] DATAJPA-1241 - Removed dynamic check for getResultStream() on JPA query implementation classes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../repository/query/JpaQueryExecution.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java index 69fd05eb9..56d16e7e3 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java @@ -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 iter = persistenceProvider.executeQueryWithResultStream(jpaQuery);