想在hibernate语句查询时 检测运行条数和运行时间,
以下是代码  请各位大虾帮忙指点
public Criteria createDeliveryOrder(long companyId, int type, long userId, Integer state, Integer userType,   DetachedCriteria aoiDet, boolean b) { Criteria cri = createCriteria(); if (companyId == 0 && type == 1 && state == 1) {
cri.add(Restrictions.eq("doiStatus", (short) 0));
}
cri.add(Subqueries.propertyIn("advertiseOrderInfo.advertiseOrderId", aoiDet)); if (type == 2 && userType == 2) {
cri.add(Restrictions.eq("doiStatus", (short) 8));
}
if (b) {
cri.addOrder(Order.desc("deliveryOrderId"));
}

MBeanServer server = MBeanServerFactory.createMBeanServer(); 

Hashtable tb = new Hashtable();

tb.put("type", "statistics");
tb.put("sessionFactory", "all");
ObjectName on;
try {
on = new ObjectName("hibernate", tb);
StatisticsService stats = new StatisticsService(); 
stats.setSessionFactory(getSessionFactory()); 

server.registerMBean(stats, on);
} catch (MalformedObjectNameException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (InstanceAlreadyExistsException e) {
e.printStackTrace();
} catch (MBeanRegistrationException e) {
e.printStackTrace();
} catch (NotCompliantMBeanException e) {
e.printStackTrace();



Statistics sta = getSessionFactory().getStatistics();
sta.setStatisticsEnabled(true); double queryCacheHitCount = sta.getQueryCacheHitCount();
double queryCacheMissCount = sta.getQueryCacheMissCount();
double queryCacheHitRatio = queryCacheHitCount / (queryCacheHitCount + queryCacheMissCount); String[] aa = sta.getQueries(); long rowCount = sta.getQueryStatistics( cri.toString()).getExecutionRowCount();
String hql = "select * from AdvertiseInfo";
long avgTime = sta.getQueryStatistics(hql).getExecutionAvgTime();
System.out.println("记录数: " + rowCount + "平均时间: " + avgTime);


EntityStatistics entityStats = sta.getEntityStatistics( DeliveryOrderInfo.class.getName() );

long bb = entityStats.getLoadCount();

return cri;
}这是本人在测试  ,但怎么测试 getExecutionAvgTime,getExecutionRowCount都是0
好像没进行统计,
能帮指出在哪打开 怎么打开 ,搞了一天了 头都晕了,谢谢了