Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy breaks SQLExtractor #668

Open
ymajoros opened this issue Oct 23, 2023 · 2 comments
Open

proxy breaks SQLExtractor #668

ymajoros opened this issue Oct 23, 2023 · 2 comments

Comments

@ymajoros
Copy link

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.

@vladmihalcea
Copy link
Owner

Thanks for the suggestion. You can send a Pull Request with your proposal.

ymajoros pushed a commit to ymajoros/hypersistence-utils that referenced this issue Nov 7, 2023
@ymajoros
Copy link
Author

ymajoros commented Nov 8, 2023

This pull request also solves this: #675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants