我正在尝试打印hibernate执行的SQL的统计信息,我看到hibernate支持if if set
hibernate.generate_statistics=true
我这样做了,当我打印统计信息时,我只看到在该会话中执行的本机SQL和HQL,而不是在加载实体及其子代时生成的SQL。
以下是我记录统计信息的代码
Statistics s = sessionFactory.getStatistics();
s.logSummary();
String[] queries = s.getQueries();
System.out.println("Total Queries Executed ==>> " + queries.length);
for(int i = 0; i < queries.length; i++) {
System.out.println(queries[i]);
long et = s.getQueryStatistics(queries[i]).getExecutionAvgTime();
System.out.println("==>> Average Execution Time = " + et);
et = s.getQueryStatistics(queries[i]).getExecutionMaxTime();
System.out.println("==>> Max Execution Time " + et);
et = s.getQueryStatistics(queries[i]).getExecutionMinTime();
System.out.println("==>> Min Execution Time " + et);
}
这只打印HQL或本机SQL,但不打印加载实体时执行的那些,如下所示
session.get(Employee.class, 123456L);
如何获取生成的SQL的统计信息?