Add HQL query to warning about positional parameter usage
Description
follows up on
is followed up by
Activity
Former userMarch 3, 2015 at 9:30 AM
Thanks for the feedback!
Carsten HammerMarch 2, 2015 at 7:57 AM
Thank you very much - works fine for me!
Best regards,
Carsten
Former userFebruary 18, 2015 at 7:38 PM
The line and column in the log message refers to a location in the HQL statement, not the SQL statement (the SQL statement has not been generated yet).
I've added the HQL query string to the log message.
Pushed to master and 4.3 branches.
Carsten HammerFebruary 18, 2015 at 7:34 AM
Hi Gail,
yes and no. I think the query displayed is the query referenced in the warning. But I get many thousands of messages from many concurrent threads after I activate this setting. And I am only interested in these warnings to find locations of code that has to be redesigned in a big legacy application. It is a little bit difficult to do it currently though not impossible. That is why I set "minor" priority..
Imho to write warnings for these positional parameters is a very good thing but it seems to me it is done only half way as the query referenced is not easy to locate. The warning is written even if you do not output the sql query while it references the query. I understand that collecting information that is available somewhere else to have it displayed together with this log message is against several design principles. But maybe it is possible to provide a listener interface to listen on queries hibernate creates?
Best regards,
Carsten
Former userFebruary 17, 2015 at 10:02 PM
Please try setting hibernate.show_sql=true. Does that provide what you're looking for?
For an update from a former hibernate version you might get a lot of "WARN : org.hibernate.hql.internal.ast.HqlSqlWalker - [DEPRECATION] Encountered positional parameter near line.." warnings. Unfortunately there is no way to find out what the query is and where the query is located in the code. The code in HqlSqlWalker does output line and position of an query not revealed:
LOG.warnf(
"[DEPRECATION] Encountered positional parameter near line %s, column %s. Positional parameter " +
"are considered deprecated; use named parameters or JPA-style positional parameters instead.",
inputNode.getLine(),
inputNode.getColumn()
);
It would be helpful if it 1) either would be possible to display the query in question or 2) to create a stacktrace at this point. Linenumber and column are not sufficient if you suppress everything else.
A way to hook a query listener in on demand that gets some diagnostic information (the query, maybe parsing information, warnings, processing time, and so on) would be great but of course that would be just nice to have.