Hibernate and Spring modify query Before Submitting to DB

前端 未结 1 533
借酒劲吻你
借酒劲吻你 2021-01-23 17:33

I have a Hibernate query that is configured to execute with Spring Data (the @Repository) annotation. I want to catch the query before it is submitted to the DB and when a speci

相关标签:
1条回答
  • 2021-01-23 18:21

    If you want to modify the query after the prepared statement, you can do it into an Hibernate Interceptor, and register it during Spring DB Configuration.

    Your MyInterceptor either should implements Hibernate Interceptor.class or extends EmptyInterceptor.class. The method you are looking for is:

    public String onPrepareStatement(String sql);
    

    If you need something more, you could give a try with the Event Listeners, but I am not sure there is one for your case.

    Here some documentation:

    Hibernate 4.0 Interceptors and events How to integrate an Interceptor with Spring

    0 讨论(0)
提交回复
热议问题