title: When does Hibernate print statistics?
body: <p>I've recently integrated hibernate into my webapp and am trying to see the performance impact/frequency of db calls that are happening.</p>
  
  <p>After enabling <code>show_sql</code> and <code>generate_statistics</code>, when I run the application I see the sql queries run by hibernate and also hibernate statistics. Eg:</p>
  
  <pre><code>08:04:53.724 [http-apr-8080-exec-1] INFO  o.h.e.i.StatisticalLoggingSessionEventListener - Session Metrics {
  85648 nanoseconds spent acquiring 1 JDBC connections;
  0 nanoseconds spent releasing 0 JDBC connections;
  0 nanoseconds spent preparing 0 JDBC statements;
  0 nanoseconds spent executing 0 JDBC statements;
  0 nanoseconds spent executing 0 JDBC batches;
  0 nanoseconds spent performing 0 L2C puts;
  0 nanoseconds spent performing 0 L2C hits;
  0 nanoseconds spent performing 0 L2C misses;
  0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
  0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
  }
  </code></pre>
  
  <p>However the statistics statement gets printed multiple times per api call while the query statements are much lower in number. Also, its very rare to see a non zero value for any other metric except <code>acquiring 1 JDBC connections</code> in Statistics logs.</p>
  
  <p>So when exactly does the logger run and what am I doing wrong to get so many metric logs?</p>
  
  <p>Thanks</p>