ssh中org.springframework.orm.hibernate4.support.OpenSessionInViewFilter的作用及配置
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter 是Spring为我们解决Hibernate的Session的关闭与开启问题。
Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层,当 Web 层访问到那些需要延迟加载的数据时,由于加载领域对象的 Hibernate Session 已经关闭,这些导致延迟加载数据的访问异常
(eg: org.hibernate.LazyInitializationException:(LazyInitializationException.java:42)
- failed to lazily initialize a collection of role: cn.easyjava.bean.product.ProductType.childtypes, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.easyjava.bean.product.ProductType.childtypes, no session or session was closed)。
用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。目的是为了实现"Open Session in View"的模式。例如: 它允许在事务提交之后延迟加载显示所需要的对象。
而Spring为我们提供的OpenSessionInViewFilter过滤器为我们很好的解决了这个问题。
OpenSessionInViewFilter的主要功能是用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。目的是为了实现"Open Session in View"的模式。例如: 它允许在事务提交之后延迟加载显示所需要的对象。
OpenSessionInViewFilter 过滤器将 Hibernate Session 绑定到请求线程中,它将自动被 Spring 的事务管理器探测到。所以 OpenSessionInViewFilter 适用于 Service 层使用HibernateTransactionManager 或 JtaTransactionManager 进行事务管理的环境,也可以用于非事务只读的数据操作中。
<filter>
<filter-name>Spring OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param> <!--
指定org.springframework.orm.hibernate3.LocalSessionFactoryBean在spring配置文件中的名称,默认值为sessionFactory
如果LocalSessionFactoryBean在spring中的名称不是sessionFactory,该参数一定要指定,否则会出现找不到sessionFactory的例外
-->
<param-name>sessionFactoryBean</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
ssh中org.springframework.orm.hibernate4.support.OpenSessionInViewFilter的作用及配置的更多相关文章
- org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
---恢复内容开始--- /* * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache ...
- org.springframework.orm.hibernate4.support.OpenSessionInterceptor
/* * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Vers ...
- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter作用
在Spring与Hibernate集成时在web.xml要加入这样的过滤器: <filter> <filter-name>openSessionInView</filte ...
- Caused by: java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.HibernateTemplate
1.错误描述 严重: Context initialization failed org.springframework.beans.factory.CannotLoadBeanClassExcept ...
- SSH中懒加载异常--could not initialize proxy - no Session
SSH进行关联的表进行显示时出现的问题,老是显示你的OGNL表达式错误,但是找了很久确实没错,在网上找了一下,下面的这个方法本人认为是最有效的方法(已经测试可以使用) 在web.xml中加入 程序代码 ...
- ssh中的 Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
这个错误我整理了 半天才发现问题的存在. 尝试了网上的很多办法,但是最后都没有达到效果. 包括这两种: 第一种: web.xml种的配置 <filter> <filter-name ...
- ssh中Hibernate懒加载,session问题的学习与理解
交代本项目中要求获取session的方式如下: public Session getCurrentSession() { // 增删改使用的session,事务必须是开启的(Required,即pro ...
- SSH中使用延迟加载报错Exception occurred during processing request: could not initialize proxy - no Session
17:40:17,249 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred during processing request: ...
- 二 SSH整合:Spring整合Hibernate,无障碍整合&无核心配置整合,Hibernate模版常用方法,
重建SSH项目 java项目可以直接复制,但是web项目除了改名字还要该配置,如下: 方式一:无障碍整合:带Hibernate配置文件 <?xml version="1.0" ...
随机推荐
- iOS 域名解析
如何在iOS下进行域名的解析? /** * 域名解析ip * * @param hostName 域名 * * @return ip */ +(NSString *) getIPWithHost ...
- IOS开发基础知识--碎片27
1:iOS中的round/ceil/floorf extern float ceilf(float); extern double ceil(double); extern long double c ...
- Wintel物联网平台-Windows IoT新手入门指南
1. 引言 近期,微软跟进物联网的速度也在不断加速,除了微软手环,.NET MicroFramework,还有一个叫做Windows IoT的项目.该项目早在今年4月份的Build大会上就提出来了,7 ...
- ORA-14452的出现原因解析及解决方法
在删除临时表时遇到了ORA-14452错误:ORA-14452: attempt to create , alert or drop an index on temporary table alrea ...
- Symantec Backup Exec Agent For Linux防火墙问题
如果在Unix或Linux安装配置好了Symantec Backup Exec Agent For Linux,但是在Symantec Backup Exec服务端无法访问Symantec Backu ...
- date命令总结
date命令是显示或设置系统时间与日期 date(选项)(参数) -d<字符串>:显示字符串所指的日期与时间.字符串前后必须加上双引号: -s<字符串>:根据字符串来设置日期与 ...
- webapi 控制器接收POST参数时必须以对象的方式接收
webapi 控制器接收POST参数时必须以对象的方式接收
- iOS AppIcon尺寸和上传ITunes构建版本尺寸
避免忘记. 记录一下 App Icon: 29X2940X4058X5876X7687X8780X80120X120152X152167X167180X180 ITunes构建版本: 1242 x 2 ...
- 【Linux】Vim语法高亮显示
配置vim 1. 安装vim2. 在hom创建文件.vimrc3. 修改.vimrc内容 syntax=on4. 打开vim,完成! 注: 预转的Vim(比如我现在的Linux Mint)不是完整版, ...
- Ngnix下安装python2.7
1 mkdir data 创建data目录 2 cd data 切换到data目录下 3 mkdir python27 创建python27目录 4 将下载好的python压缩包放在python27目 ...