Question

HQL queries are converted to SQL.

I would like my program to have the complete SQL string before it is sent to my database.

Can I do this?


Notes:

I can see the SQL sent to the database by setting

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

in my cfg.xml

Was it helpful?

Solution

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

See Interceptor javadocs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top