@@ -130,25 +130,11 @@ private static List<Object> getSQLParametersFromJPAQuery(Query query) {
130
130
* @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
131
131
*/
132
132
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 ;
147
136
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 );
152
137
}
138
+ return Optional .empty ();
153
139
}
154
140
}
0 commit comments