Skip to content

Commit 8b260be

Browse files
committed
incorporating feedback from vladmihalcea#673 (comment)
1 parent c4e39ef commit 8b260be

File tree

1 file changed

+4
-18
lines changed
  • hypersistence-utils-hibernate-62/src/main/java/io/hypersistence/utils/hibernate/query

1 file changed

+4
-18
lines changed

hypersistence-utils-hibernate-62/src/main/java/io/hypersistence/utils/hibernate/query/SQLExtractor.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,11 @@ private static List<Object> getSQLParametersFromJPAQuery(Query query) {
130130
* @return the unproxied Hibernate query, or original query if there is no proxy, or null if it's not an Hibernate query of required type
131131
*/
132132
private static Optional<QuerySqmImpl<?>> getSqmQueryOptional(Query query) {
133-
try {
134-
if (query instanceof QuerySqmImpl) {
135-
QuerySqmImpl<?> querySqm = (QuerySqmImpl<?>) query;
136-
return Optional.of(querySqm);
137-
}
138-
if (!Proxy.isProxyClass(query.getClass())) {
139-
return Optional.empty();
140-
}
141-
// is proxyied, get it out
142-
InvocationHandler invocationHandler = Proxy.getInvocationHandler(query);
143-
Class<?> innerClass = invocationHandler.getClass();
144-
Field targetField = innerClass.getDeclaredField("target");
145-
targetField.setAccessible(true);
146-
QuerySqmImpl<?> querySqm = (QuerySqmImpl<?>) targetField.get(invocationHandler);
133+
Query unwrappedQuery = query.unwrap(Query.class);
134+
if (unwrappedQuery instanceof QuerySqmImpl) {
135+
QuerySqmImpl<?> querySqm = (QuerySqmImpl<?>) unwrappedQuery;
147136
return Optional.of(querySqm);
148-
} catch (NoSuchFieldException exception) {
149-
return Optional.empty(); // not an Hibernate query
150-
} catch (IllegalAccessException exception) {
151-
throw new IllegalStateException(exception);
152137
}
138+
return Optional.empty();
153139
}
154140
}

0 commit comments

Comments
 (0)