[hibernate-dev] SQL query interceptor

Vlad Mihalcea mihalcea.vlad at gmail.com
Wed Jun 8 07:46:49 EDT 2016


During testing, it's very useful to have an SQL query interceptor that we
can inspect to see if the generated SQL query contains a certain SQL clause.
There are multiple ways we could implement this kind of feature:

1. We could add a public String[] getSQLQueries(); in the Statistics
2. We could define a SQLStatementInterceptor interface that can be provided
via some configuration property.
   The SqlStatementLogger.logStatement could call the
SQLStatementInterceptor as well.
3. We could provide a way to provide a custom SQLStatementLogger class, so
that users can intercept statements via their custom SQLStatementLogger.

Currently, the only solution is to overwrite the sqlStatementLogger field
of the JdbcServicesImpl via Reflection, which is rather a hack.
What do you think?


More information about the hibernate-dev mailing list