Can Spring Hibernate interecpt queries?
Clash Royale CLAN TAG #URR8PPP Can Spring Hibernate interecpt queries? I am developing an application where i need to intercept all sql queries made, and add something like "WHERE customer_id=id" after every query so don't have to add the clause every time i use a query. Is there a way to filter every query before it's sent to the database? 1 Answer 1 Yes, hibernate provide class EmptyInterceptor, We have to extend this class and overrides all methods. Before going to this step we have to register our interceptor to hibernate session. // Logging Interceptor.. public class LoggingInterceptor extends EmptyInterceptor { private static final long serialVersionUID = 1L; // Define a static logger private static Logger logger = LogManager.getLogger(LoggingInterceptor.class); // 1) save @Override public boolean onSave(Object entity, Serializable id, Object state, String propertyNames, Type types) logger.info("onSave method is called."); System.out...