StatementInspector for specific packages only

Hello,

We are using Spring with Hibernate. We have a certain requirement to customize a sql query before sending it to the database. A StatementInspector is a good start, however we would like to invoke it only for sql generated by a particular dao package. I know I can configure it globally and in the inspect method use filters to filter certain keywords. This approach is a bit complicated because of the complexity of our db. I was wondering if there’s a simple way to just invoke it for a certain package. We don’t want to create a new non spring managed session to handle this as the root service is transactional. This will lead to multiple sessions per transaction leading to perf issues.

Hello @johndoe, as you can read from StatementInspector’s javadoc you can either configure one for all sessions created by a given session factory or have a dedicated instance for certain sessions. You could, for example, always configure sessions opened for the “packages” you mentioned to use the inspector implementation, without affecting others. Now how you would go about doing all this with Spring, I’ve no idea, you’re going to have to look into that yourself.

What is the reason you need to modify SQL statements? Perhaps there are better approaches to solve your specific needs.