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" ...
随机推荐
- UIScrollView的delegate方法妙用之让UICollectionView滑动到某个你想要的位置
一个UICollectionView有好多个cell,滑动一下,谁也不知道会停留在哪个cell,滑的快一点,就会多滑一段距离,反之则会滑的比较近,这正是UIScrollview用户体验好的地方. 如果 ...
- [Animatable Properties](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html)
 
- 深入浅出React Native 3: 从零开始写一个Hello World
这是深入浅出React Native的第三篇文章. 1. 环境配置 2. 我的第一个应用 将index.ios.js中的代码全部删掉,为什么要删掉呢?因为我们准备从零开始写一个应用~学习技术最好的方式 ...
- ThinkPHP3快速入门教程三:查询语言
一.查询语言简介: ThinkPHP内置了非常灵活的查询方法,可以快速的进行数据查询操作,查询条件可以用于读取.更新和删除等操作,主要涉及到where方法等连贯相关方法操作即可, 此框架查询系统可以解 ...
- C#和ASP.NET之事件
事件是一种用于类和类之间传递消息或触发新的行为的编程方式.通过提供事件的句柄,能够把控件和可执行的代码联系在一起, 如用户单击Button控件触发Click事件后就执行相应的事件处理代码. 事件的声明 ...
- Linux如何查找大文件或目录总结
在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件 ...
- delete语句跑了3个小时分析以及关于并行的一些知识
=====================START==================================== 闲来无事,看了下数据库跑的long running sql, SQL> ...
- PHP中的回调函数和匿名函数
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- SQL闲杂知识点汇总【2015年12月】
2015.12.14 知识点1:DEFAULT VALUES实现插入行 --临时创建临时表 CREATE TABLE [dbo].[tblTmp] ( iTmpID ,) NOT NULL PRIMA ...
- Python安装
Win10 安装Python 1.官网下载Python安装包,一直点击下一步进行安装 安装完Python后要设置环境变量,右键我的电脑-->属性-->高级系统设置-->环境变量--& ...