How To Intercept The Generated SQL For Logging Or Altering
Description: Sometimes we need to intercept the generated SQL that originates from Spring Data, EntityManager
, Criteria API, JdbcTemplate
and so on. This can be done as in this sample application. After interception, you can log, modify or even return a brand new SQL that will be executed in the end.
Key points:
- define an implementation of Hibernate
StatementInspector
SPI - configure this SPI in
application.properties
viaspring.jpa.properties.hibernate.session_factory.statement_inspector