I’m using Play Framework and I would like to retrieve the queries performed by Hibernate.
I know there is a setting in application.conf (jpa.debugSQL=true) to display the queries in the console but what I would like to do is to retrieve these queries from the code to display them by myself for the user (like an admin interface in the website to see the queries for each page request).
Thank you for your help !
It should be quite easily achievable if you are familiar with log4j (or any other similar logging framework).
You could write a custom appender which would be configured to receive all events from
org.hibernate.SQL(this is the package which provides SQL output). This appender would put all events into some FIFO buffer. This would allow you to keep lastnlog entries in memory.The rest, I guess, is as easy as showing the buffer contents in your webapp.
EDIT: example of how things might look like:
log4j config:
Java code: