Trying to add a comment to all MySQL Select Queries in my web application at runtime.
For example, the original queries in the code looks like:
select a,
Create a Custom DB Interceptor
package com.felix.dao.interceptor;
import org.hibernate.EmptyInterceptor;
public class CustomDBInterceptor extends EmptyInterceptor {
@Override
public String onPrepareStatement(String sql) {
String commentStr = "/*Comment*/"
return super.onPrepareStatement(commentStr+sql);
}
}
In the Spring Context file, configure the Interceptor for the session factory:
...
Make sure the Custom DB Interceptor does not have a cyclic dependency on the sessionFactory.
With the above, all queries fired through the session factory, are intercepted, modified and then passed to the onPrepareStatement method.