关于hibernate 的session和缓存问题。
最近在用s2sh做一个小项目。
其中。hibernate中的一对多,多对1级查询出现延时加载的问题。
然后我配置了spring的openSessionInViewFilter。
然后新增不会出现问题。但是更新出现问题。
这个应该是缓存问题。没有好的解决方案。就改用了merge()方法。
但是做批量删除的时候
还是挂掉了。错误和上面一样。
web。xml
其中。hibernate中的一对多,多对1级查询出现延时加载的问题。
然后我配置了spring的openSessionInViewFilter。
然后新增不会出现问题。但是更新出现问题。
org.springframework.orm.hibernate3.HibernateSystemException: Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)这个应该是缓存问题。没有好的解决方案。就改用了merge()方法。
但是做批量删除的时候
String hql="from Roles where id in(";
for(int i=0;i<roles.length-1;i++)
{
hql+=roles[i]+",";
}
hql+=roles[roles.length-1]+")";
this.getHibernateTemplate().clear();
this.getHibernateTemplate().flush();
List<Roles> list=this.getHibernateTemplate().find(hql);
this.getHibernateTemplate().deleteAll(list);还是挂掉了。错误和上面一样。
web。xml
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
...全文
相关推荐
深入剖析hibernate的n+1问题和缓存问题
深入理解hibernate的缓存问题和配置,提高使用hibernate的效率
Hibernate事务缓存
详细的介绍了Hibernate中的事务配置和缓存使用。
Hibernate缓存详解[文].pdf
Hibernate缓存详解[文].pdf
hibernate的一级缓存和二级缓存
hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存
Hibernate一级缓存和二级缓存
NULL 博文链接:https://12345678.iteye.com/blog/721910


