SQL string from HQL query?

HQL queries are converted to SQL.

I want my program to have a full SQL string before submitting it to my database.

Can I do it?


Notes:

I see that SQL is sent to the database by setting

<property name="hibernate.show_sql">true</property>

in my cfg.xml

+3
source share
1 answer

I believe that you can create a class that implements org.hibernate.Interceptor, register it Configuration.setInterceptor(Interceptor)at startup, and then access SQL through a callback Interceptor.onPrepareStatement(String sql).

See javadocs interceptor

+4
source

Source: https://habr.com/ru/post/1703000/


All Articles