Hi everyone!
I need to get the SQL that would be executed by a Query (QuerySqmImpl). In Hibernate 5 I used a QueryTranslator, but that class doesn’t seem to be available anymore.
I’m using an idea based on a library I’ve found called “hypersistence”, but it calls a private method called “ConcreteSqmSelectQueryPlan.buildCacheableSqmInterpretation”. The idea works, but I have to create a copy of the original Query, or else I get a NullPointerException at SqmUtil:
final SqmParameter<?> expansionSqmParam = expansions.get( expansionPosition++ );
final List<JdbcParametersList> jdbcParamBinds = jdbcParamMap.get( expansionSqmParam );
for ( int i = 0; i < jdbcParamBinds.size(); i++ ) {
At that point, jdbcParamBinds is null if you call the method twice with the same Query.
As I said, it works, but it’s using internal methods that we should not be using. Is there any other cleaner, nicer approach for this task? I’ve searched the documentation and the internet, but so far without success.
Best regards.