个人理解,不对的大家可以指正
新增,修改操作频繁,数据量过大,方法会时好时坏,本来昨天还好好的,今天就一直报错,原来只需要刷新下,释放下缓存
1。在Hibernate中增加如下
public void flush() { getHibernateTemplate().flush(); }//刷新缓存 public void evict(Object entity) { getHibernateTemplate().evict(entity); }//清空缓存
2.在新增,或修改方法中如下
//定义一个int类型计数
int a = 0;
for(int i = 0; i<list.size();i++){
//每新增,或修改加1
a++;
//每新增,或修改100条刷新缓存,并清空缓存
if(a%100 == 0){
//调用刷新缓存方法
列:getHibernateTemplate().flush();
//调用清空缓存方法
列:getHibernateTemplate().evict(entity);
}
}
每新增、修改 100条数据则清空一下缓存,就不会报这个错了。