Open
Description
SQLExtractor.from(TypedQuery)
didn't work from some of my use cases: for some reason, I got a proxy for my TypedQuery instance, which isn't assignable from QuerySqmImpl.
I could solve it with following workaround:
private Query getHibernateQuery(TypedQuery<?> typedQuery) {
try {
if (typedQuery instanceof QuerySqmImpl) {
return typedQuery;
}
// is proxyied, get it out
InvocationHandler invocationHandler = Proxy.getInvocationHandler(typedQuery);
Class<?> innerClass = invocationHandler.getClass();
Field targetField = innerClass.getDeclaredField("target");
targetField.setAccessible(true);
return (Query) targetField.get(invocationHandler);
} catch (NoSuchFieldException | IllegalAccessException exception) {
throw new RuntimeException(exception);
}
}
I suggest including it in SQLExtractor.
Metadata
Metadata
Assignees
Labels
No labels