Reputation: 13150
How do I count the number of SQL queries made to a H2 (1.3.172) database using Hibernate (4.3.11).
I just require a total count at the end of a long running task (several hours), I don't need a trace of the actual queries themselves.
Is there a simple way to do this, in theory I could do with either Hibernate or H2 but I couldn't find a solution.
Upvotes: 2
Views: 532
Reputation: 5097
This article should help you out.
https://www.thoughts-on-java.org/hibernate-tips-count-executed-queries-session/
In summary, you first need to add this property to your configuration.
<property name="hibernate.generate_statistics" value="true" />
Then, you have to add the following lines in your DAOs.
Statistics stats = sessionFactory.getStatistics();
long queryCount = stats.getQueryExecutionCount();
Hope it helps.
Upvotes: 1