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

spring的openSessionInView一些注意要义

2012-11-10 
spring的openSessionInView一些注意要点spring的openSessionInViewFilter能将session的生命周期延长到请求

spring的openSessionInView一些注意要点
spring的openSessionInViewFilter能将session的生命周期延长到请求完成后结束。 解决了在hibernate的load方法中,并未把数据真正获取时就关闭了session,导致出现了异常的问题。

在web.xml中,openSessionInViewFilter要配载struts的过滤器之前才能起作用;另外还需要注意的是:若用到hibernateTemplate,但未声明事务边界,openSessionInView即默认认为事务是readyOnly,所以此时save数据会抛出异常:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
我的解决办法是在service的set方法上加 @Transactional

热点排行