在Spring与Hibernate集成时在web.xml要加入这样的过滤器:
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
请问这个过滤器的作用是什么???
OpenSessionInViewFilter是Spring提供的一个针对Hibernate的一个支持类,其主要意思是在发起一个页面请求时打开Hibernate的Session,一直保持这个Session,直到这个请求结束,具体是通过一个Filter来实现的。
由于Hibernate引入了Lazy Load特性,使得脱离Hibernate的Session周期的对象如果再想通过getter方法取到其关联对象的值,Hibernate会抛出一个LazyLoad的Exception。所以为了解决这个问题,Spring引入了这个Filter,使得Hibernate的Session的生命周期变长。
分享到:
相关推荐
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <param-name>singleSession <param-value>true <param-name>flushMode <param-value>AUTO <filter-name>...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter ``` - `OpenSessionInViewFilter`过滤器可以开启Hibernate的延迟加载功能,使得在一个HTTP请求范围内保持Hibernate Session的...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter ``` **2. Struts配置文件(struts-config.xml)** Struts配置文件用于定义Action映射、Form Bean等。例如: ```xml ...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <param-name>singleSession <param-value>true <filter-name>hibernateFilter *.do ``` 这里`singleSession`参数...
`org.springframework.orm.hibernate3.support.OpenSessionInViewFilter` - **定义**:`OpenSessionInViewFilter`是Spring与Hibernate整合时使用的过滤器之一,用于在视图渲染过程中保持Hibernate Session的打开...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <filter-name>lazy *.do <filter-name>lazy *.jsp <filter-name>lazy <url-pattern>/dwr/* ``` - `<filter>`...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <!-- 设置Flush Mode --> <param-name>flushMode <param-value>AUTO ``` #### 配置示例 下面分别给出使用...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <!-- ExtremeTable Excel/PDF 导出过滤器 --> <filter-name>eXtremeExport <filter-class>org.extremecomponents....
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <filter-name>hibernatelazymanagerfilter <url-pattern>/* ``` #### 2. **struts-config.xml** —— Struts框架的配置文件 `struts...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <param-name>singleSession <param-value>true <filter-name>openSessionInViewFilter <url-pattern>/* ``` ...
- `<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>`:OSIV模式允许在视图层(如JSP)处理请求时仍然保持数据库会话,以解决延迟绑定问题。`...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <param-name>singleSession <param-value>true <filter-name>hibernateFilter *.do ``` 在`web.xml`中定义`...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <filter-name>OpenSessionInView *.do 2,LazyInitializationException异常说明 1,对于集合属性...
1. **添加过滤器定义**:在`web.xml`文件中定义过滤器,指定过滤器类为`org.springframework.orm.hibernate3.support.OpenSessionInViewFilter`。 2. **初始化参数设置**: - `singleSession`: 设置为`true`表示在...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <!--...--> ``` 此过滤器保持一个打开的Hibernate Session直到视图渲染完成,确保了事务的一致性。 #### 6. Struts2过滤器 `...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <filter-name>hibernateFilter <url-pattern>/* ``` 为了防止懒加载异常,可以配置一个过滤器,使得每个请求都在一个...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter ``` 4. 添加Struts2的过滤器,拦截URL请求并路由到相应的Action: ```xml <filter-name>struts2 <filter-class>org....
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <filter-name>OpenSessionInViewFilter *.action ``` 3. **配置Struts2过滤器**: 最后,配置Struts2的过滤器`...
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <filter-name>OpenSessionInViewFilter <url-pattern>/* ``` #### 4. 新建包并导入配置文件 接下来,根据项目结构创建...
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter <!-- 设置监听加载上下文 --> <filter-name>struts2 org.apache.struts2.dispatcher.FilterDispatcher ``` 3. **Filter ...