From 0cd3b0f6879944dfb8c61a89e6c4fecaad7a98f3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 4 Apr 2018 11:57:01 +0200 Subject: [PATCH] DATAJPA-1300 - Polishing. Original pull request: #264. --- .../repository/query/QueryParameterSetter.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryParameterSetter.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryParameterSetter.java index 35fcd9f5f..2010fc3ed 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryParameterSetter.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryParameterSetter.java @@ -140,23 +140,28 @@ interface QueryParameterSetter { } /** - * Returns the actual target Query instance, even if the provided query is a {@link Proxy} based on + * Returns the actual target {@link Query} instance, even if the provided query is a {@link Proxy} based on * {@link org.springframework.orm.jpa.SharedEntityManagerCreator.DeferredQueryInvocationHandler}. * - * @param query a Query instance, possibly a Proxy. + * @param query a {@link Query} instance, possibly a Proxy. * @return the class of the actual underlying class if it can be determined, the class of the passed in instance * otherwise. */ - private Class unwrapClass(Query query) { + private static Class unwrapClass(Query query) { + + Class queryType = query.getClass(); try { - return query instanceof Proxy ? query.unwrap(null).getClass() : query.getClass(); + return Proxy.isProxyClass(queryType) // + ? query.unwrap(null).getClass() // + : queryType; + } catch (RuntimeException e) { LOGGER.warn("Failed to unwrap actual class for Query proxy.", e); - return query.getClass(); + return queryType; } } }