首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

解决hibernate查询时,自动更新有关问题

2012-11-10 
解决hibernate查询时,自动更新问题对hibernate的session操作时时,默认的FlushModel时auto的,对于查询,不需

解决hibernate查询时,自动更新问题

对hibernate的session操作时时,默认的FlushModel时auto的,对于查询,不需要Flush。hibernate建议在session的操作前,设置 flush mode? 为MANUAL 的(还有NRVER,但hibernate是deprecated的)。

?

?

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;}

?

热点排行