默认监控是关闭的,在hibernate.properties中打开监控设置
#监控二级缓存
hibernate.generate_statistcs true
测试:
@Test
public void t2(){
Session session = HibernateUtil.getInstance().getSession();
session.beginTransaction();
Emp e = (Emp) session.get(Emp.class, 1);
//System.out.println(e.getId());
session.getTransaction().commit();
Statistics st = HibernateUtil.getInstance().getsf().getStatistics();
System.out.println(st);
session.close();
}
结果如下
Statistics[start time=1379397879484,sessions opened=0,sessions closed=0,transactions=0,successful transactions=0,optimistic lock failures=0,flushes=0,connections obtained=0,statements prepared=0,statements closed=0,second level cache puts=0,second level cache hits=0,second level cache misses=0,entities loaded=0,entities updated=0,entities inserted=0,entities deleted=0,entities fetched=0,collections loaded=0,collections updated=0,collections removed=0,collections recreated=0,collections fetched=0,naturalId queries executed to database=0,naturalId cache puts=0,naturalId cache hits=0,naturalId cache misses=0,naturalId max query time=0,queries executed to database=0,query cache puts=0,query cache hits=0,query cache misses=0,update timestamps cache puts=0,update timestamps cache hits=0,update timestamps cache misses=0,max query time=0]