对hibernate的session操作时时,默认的FlushModel时auto的,对于查询,不需要Flush。hibernate建议在session的操作前,设置 flush mode  为MANUAL

 

 

For a logically "read only" session, it is reasonable to set the session's flush mode to FlushMode.MANUAL at the start of the session (in order to achieve some extra performance).

 

dao查询代码:

 

@SuppressWarnings("unchecked")
	public List searchByHql(final String hql) {
       System.out.println("searchByHql:"+hql);
		HibernateCallback cb = new HibernateCallback() {
			public Object doInHibernate(Session session) {
				session.setFlushMode(FlushMode.MANUAL);
				Query q = session.createQuery(hql);
				return q.list();
			}
		};
		List list = (List) getHibernateTemplate().execute(cb);
		return list;
	}