Skip to content

proxy breaks SQLExtractor #668

Open
Open
@ymajoros

Description

@ymajoros

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions