关于hibernate 的session和缓存问题。

jiyou1992989 jiyou1992989 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在用s2sh做一个小项目。
其中。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>



...全文
评论 2
收藏 已收藏
分享
返回顶部
jiyou1992989
Java EE 67,535 成员 225,843 内容