openSessionInView的使用及注意事项
2011-11-23 13:20
357 查看
用途:可以将session的作用域扩大用于ssh整合中。如hibernate中使用load()方法时在struts中session已经关闭 则会引起错误
<!-- 将session的生命周期托管给自定义的filter管理,以延长其生命周期 -->
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
使用时注意
(1)在web.xml 中配置时需要配置在struts2的filter的前面。因为filter有先后顺序。
(2)若配置了openSessionInView这个filter,则需要在spring中添加声明式的事物管理。否则只能进行读操作,在进行写操作时则会产生
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. 这样的异常。
<!-- 将session的生命周期托管给自定义的filter管理,以延长其生命周期 -->
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
使用时注意
(1)在web.xml 中配置时需要配置在struts2的filter的前面。因为filter有先后顺序。
(2)若配置了openSessionInView这个filter,则需要在spring中添加声明式的事物管理。否则只能进行读操作,在进行写操作时则会产生
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. 这样的异常。
相关文章推荐
- 使用OpenSessionInViewFilter的注意事项
- 使用 OpenSessionInViewFilter 注意事项
- OpenSessionInViewFilter 配置注意事项
- 使用OpenSessionInView解决懒加载需要注意的问题
- 使用struts2 的jsonplugin插件与opensessioninview和hibernate延迟加载时遇到的问题
- 使用Spring OpenSessionInViewFilter的缺点
- 使用OpenSessionInViewFilter 发生异常: No bean named 'sessionFactory'
- 解决了Hibernate+Spring+Struts架构使用OpenSessionInView的问题
- Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- 使用OpenSessionInViewFilter解决懒加载问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- Spring 和Struts2 整合 特别需要关注Session 关闭的问题:解决方法是使用 OpenSessionInViewFilter
- 【Spring十】使用OpenSessionInView解决懒加载问题及Spring管理下的session和事务
- Spring MVC如何配置OpenSessionInViewInterceptor并结合Hibernate使用
- hibernate中使用OpenSessionInViewFilter
- 使用OpenSessionInViewFilter解决session关闭问题
- 在web.xml中配置openSessionInView的使用
- Hibernate/Spring/Struts架构使用OpenSessionInView的问题
- 使用OpenSessionInViewFilter后 could not initialize proxy no session