OpenSessionInViewFilter祥解

Android 车载开发深度解析:CarPropertyManager 核心机制与实践指南 摘要: Android Automotive OS中,CarPropertyManager作为车载信息娱乐系统的核心组件,连接应用层与车辆硬件(如车速、油量等),其架构基于分层设计(App→CarAPI→VHAL→ECU),采用发布-订阅模式实现高效数据通信。通过HIDL/AIDL跨进程交互及共享内存优化,延迟可降至2ms以下。安全机制包括分级权限控制(VISIBLE/PROTECTED/SYSTEM_RESTRICTED)和HMAC防篡改。开发时需注意监听器生命周期管理、事件合并降负载及低功耗适配。 阅读详情

 

OpenSessionInViewFilter是Spring提供的一个针对Hibernate的一个支持类,其主要意思是在发起一个页面请求时打开Hibernate的Session,一直保持这个Session,直到这个请求结束,具体是通过一个Filter来实现的。

由于Hibernate引入了Lazy Load特性,使得脱离Hibernate的Session周期的对象如果再想通过getter方法取到其关联对象的值,Hibernate会抛出一个LazyLoad的Exception。所以为了解决这个问题,Spring引入了这个Filter,使得Hibernate的Session的生命周期变长。


首先分析一下它的源码,可以发现,它所实现的功能其实比较简单:

Java代码

  1. SessionFactory sessionFactory = lookupSessionFactory(request);   
  2. Session session = null;   
  3. boolean participate = false;   
  4.   
  5. if (isSingleSession()) {   
  6.     // single session mode   
  7.     if (TransactionSynchronizationManager.hasResource(sessionFactory)) {   
  8.     // Do not modify the Session: just set the participate flag.   
  9.     participate = true;   
  10.        }    else {   
  11.     logger.debug("Opening single Hibernate Session in OpenSessionInViewFilter");   
  12.     session = getSession(sessionFactory);   
  13.     TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));   
  14.     }   
  15. } else {   
  16.     // deferred close mode   
  17.     if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {   
  18. // Do not modify deferred close: just set the participate flag.   
  19.     participate = true;   
  20.     } else {   
  21.     SessionFactoryUtils.initDeferredClose(sessionFactory);   
  22.     }   
  23. }   
  24.   
  25. try {   
  26.     filterChain.doFilter(request, response);   
  27. } finally {   
  28.     if (!participate) {   
  29.             if (isSingleSession()) {   
  30.                 // single session mode   
  31.         TransactionSynchronizationManager.unbindResource(sessionFactory);   
  32.         logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");   
  33.         closeSession(session, sessionFactory);   
  34.     }else {   
  35.         // deferred close mode   
  36.         SessionFactoryUtils.processDeferredClose(sessionFactory);   
  37.     }   
  38. }   
  39. }  

SessionFactory sessionFactory = lookupSessionFactory(request);

Session session = null;

boolean participate = false;

 

if (isSingleSession()) {

  // single session mode

  if (TransactionSynchronizationManager.hasResource(sessionFactory)) {

  // Do not modify the Session: just set the participate flag.

  participate = true;

       }  else {

  logger.debug("Opening single Hibernate Session in OpenSessionInViewFilter");

  session = getSession(sessionFactory);

  TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));

  }

} else {

  // deferred close mode

  if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {

// Do not modify deferred close: just set the participate flag.

  participate = true;

    } else {

  SessionFactoryUtils.initDeferredClose(sessionFactory);

    }

}

 

try {

  filterChain.doFilter(request, response);

} finally {

  if (!participate) {

             if (isSingleSession()) {

             // single session mode

   TransactionSynchronizationManager.unbindResource(sessionFactory);

   logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");

   closeSession(session, sessionFactory);

  }else {

   // deferred close mode

   SessionFactoryUtils.processDeferredClose(sessionFactory);

  }

}

}


在上述代码中,首先获得SessionFactory,然后通过SessionFactory获得一个Session。然后执行真正的Action代码,最后根据情况将Hibernate的Session进行关闭。整个思路比较清晰。

注意,在这里有个2个Tips:

1
)通过getSession()获得的这个Session做了一次

session.setFlushMode(FlushMode.NEVER);
有关FlushMode可以参考一下这篇文章。
http://www2.matrix.org.cn/resource/article/2006-10-08/Hibernate+FlushMode+NEVER_312bca85-5699-11db-91a0-d98dff0aec60.html
2
)Spring对拿到的Session做了一次绑定到当前线程的做法,使得这个Session是线程安全的。

从上述代码其实可以得到一些对我们的开发有帮助的结论:

1
)如果使用了OpenSessionInView模式,那么Spring会帮助你管理Session的开和关,从而你在你的DAO中通过HibernateDaoSupport拿到的getSession()方法,都是绑定到当前线程的线程安全的Session,即拿即用,最后会由Filter统一关闭。

2
)由于拿到的Hibernate的Session被设置了session.setFlushMode(FlushMode.NEVER); 所以,除非你直接调用session.flush(),否则Hibernate session无论何时也不会flush任何的状态变化到数据库。因此,数据库事务的配置非常重要。(我们知道,在调用org.hibernate.Transaction.commit()的时候会触发session.flush())我曾经见过很多人在使用OpenSessionInView模式时,都因为没有正确配置事务,导致了底层会抛出有关FlushMode.NEVER的异常。


OpenSessionInView
这个模式使用比较简单,也成为了大家在Web开发中经常使用的方法,不过它有时候会带来一些意想不到的问题,这也是在开发中需要注意的。

1.
在Struts+Spring+Hibernate环境中,由于配置的问题导致的模式失效

这个问题以前论坛曾经讨论过,可以参考一下下面这个帖子:

http://www.javaeye.com/topic/15057

2. OpenSessionInView
的效率问题
这个问题也有人在论坛提出过,Robbin曾经做过具体的测试,可以具体参考一下下面这个帖子:

http://www.javaeye.com/topic/17501

3.
由于使用了OpenSessionInView模式后造成了内存和数据库连接问题
这个问题是我在生产环境中碰到的一个问题。由于使用了OpenSessionInView模式,Session的生命周期变得非常长。虽然解决了Lazy Load的问题,但是带来的问题就是Hibernate的一级缓存,也就是Session级别的缓存的生命周期会变得非常长,那么如果你在你的Service层做大批量的数据操作时,其实这些数据会在缓存中保留一份,这是非常耗费内存的。还有一个数据库连接的问题,存在的原因在于由于数据库的Connection是和Session绑在一起的,所以,Connection也会得不到及时的释放。因而当系统出现业务非常繁忙,而计算量又非常大的时候,往往数据连接池的连接数会不够。这个问题我至今非常头痛,因为有很多客户对数据连接池的数量会有限制,不会给你无限制的增加下去。


4.
使用了OpenSessionInView模式以后取数据的事务问题

在使用了OpenSessionInView以后,其实事务的生命周期比Session的生命周期来得短,就以为着,其实有相当一部分的查询是不被纳入到事务的范围内的,此时是否会读到脏数据?这个问题我至今不敢确认,有经验的朋友请指教一下。


最后提一下OpenSessionInView模式的一些替代方案,可以使用OpenSessionInViewInterceptor来代替这个Filter,此时可以使用Spring的AOP配置,将这个Interceptor配置到你所需要的层次上去。另外就是只能使用最古老的Hibernate.initialize()方法进行初始化了。

 

YOLOv8改进策略【损失函数篇】| 替换Powerful-IoU(PIoU),增强对中等质量锚框的关注力,引导锚框更直接、高效地回归 现有基于IoU的损失函数存在不合理的惩罚因子,导致锚框在回归过程中出现面积扩大的问题,使得回归效率降低、收敛速度变慢。同时,这些损失函数在反映锚框与目标框之间的差异、考虑目标框大小以及某些情况下的性能表现等方面存在局限性。在目标检测任务中,边界框回归的损失函数对检测性能至关重要。Powerful-IoU(PIoU)及其升级版PIoU v2正是为解决现有损失函数存在的问题而设计的。本文利用PIoU改进YOLOv8的损失函数,提高模型精度。 阅读详情

相关推荐

Databricks Genie:语义编译器架构与企业级智能解析实践

语义层是现代数据平台实现自然语言查询的核心基础,其本质是将业务术语映射为可执行、可治理的数据契约。原理上依赖结构化元数据、值字典与数据血缘三支柱协同,通过分层AI代理(如Intent Parsing、Retriever、Verifier)实现意图识别→语义对齐→安全执行的闭环。技术价值在于降低SQL使用门槛的同时保障审计性、一致性和权限可控性,适用于销售运营、财务分析等一线业务场景。本文深入解析Databricks Genie作为典型语义编译器的落地逻辑,涵盖Unity Catalog知识注入、七层Agen

weixin_29053695的博客 355

OpenSessionInView详解

OpenSessionInViewFilter是Spring提供的一个针对Hibernate的一个支持类,其主要意思是在发起一个页面请求时打开Hibernate的Session,一直保持这个Session,直到这个请求结束,具体是通过一个Filter来实现的。 由于Hibernate引入了Lazy Load特性,使得脱离Hibernate的Session周期的对象如果再想通过getter方法...

luzhou33的专栏 306

U3d WebGL使用ToLua

首先我们在编辑器模式下加入Tolua插件,然后配置修改到在编辑器模式下能够正常的运行。 同个U3d 插件Build出WebGL的工程,运行的时候你会发现(有些需要把这个WebGL工程放在一个HttpServer下面,直接本地访问index.html会被拒绝,让你使用http的格式)。 当要加载完的时候会出现 To use dlopen, you need to use Emscripten'...

qq_35267906的博客 2955

OpenSessionInViewFilter的作用及原理

Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层,当 Web 层访问到那些需要延迟加载的数据时,由于加载领域对象的 Hibernate Session 已经关闭,这些导致延迟加载数据的访问异常  (eg: org.hibe

张晓 1万+

2025海外代理IP深度横评:Bright Data、IPFoxy、SmartProxy等六大服务商实战对比

本文深度横评2025年六大海外代理IP服务商(Bright Data、IPFoxy、SmartProxy、IPIPGO、Kookeey及青果网络),基于实战测试数据,从IP池质量、速度稳定性、性价比等维度进行对比。针对跨境电商、数据爬虫、社交媒体管理等不同业务场景,提供精准的选购指南与避坑建议,帮助企业用户根据自身需求选择最合适的代理IP解决方案。

weixin_29196891的博客 447

保姆级教程:用Python和PyTorch复现PTB-XL心电信号分类论文(附完整代码)

本文提供了一份详细的PTB-XL心电信号分类教程,涵盖从数据预处理到模型优化的完整流程。通过PyTorch实现三种深度学习架构(Conv1D、SincNet和熵特征融合网络),并针对医疗AI特有的类别不平衡问题提供解决方案。教程包含可运行的代码示例,帮助开发者快速复现论文结果并应用于实际心电信号分析场景。

weixin_30555125的博客 410

OpenSessionInViewFilter学习

Spring之OpenSessionInViewFilter

weixin_44877172的博客 762

高速电路设计必看:同步开关噪声问题解析

数字电路中的同步开关噪声(SSN)问题日益突出,尤其是随着高速器件应用增多。本文分析了地弹和电压弹的产生机理,指出其与电源网络电感、输出驱动电流变化率密切相关。文章详细阐述了地弹参数特征,包括峰值电压、脉冲宽度等关键指标,并探讨了负载电容、信号压摆率等因素对地弹的影响。最后提出系统化的解决方案,涵盖芯片选型、电路设计、PCB布局和后期调试等多个环节,强调通过降低回路电感和控制电流变化率来有效抑制SSN。这些措施需要在性能、成本和复杂度之间取得平衡,为高速数字电路设计提供了重要参考。

一只豌豆象的博客 311

OpenSessionInViewFilter的详细用法

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain){ try{ Session session = ...SessionFactory.getCurrentSeesion(); //得到session对象 tx = session.beginTransact

zzjstudent的专栏 1042

【PINN物理信息网络】基于PINN物理信息网络求解瞬态薛定谔方程(python)

【PINN物理信息网络】基于PINN物理信息网络求解瞬态薛定谔方程(python)

k8291121的博客 2729

Cursor自动生成测试用例

或者把你已有的规则直接复制粘贴到这个文档内(这里我用的是Markdown格式和CSV格式的测试用例生成规则,可以同时生成Markdown和CSV格式的测试用例)。在AI对话框这里,我们可以看到Cursor会逐步来帮我们生成测试用例,先分析识别需求文档,然后生成测试用例,最后会进行质量检查,确保生成的用例符合规范。生成的Markdown格式,可直接导入Xmind,生成思维导图,对应到具体的功能模块看具体的测试点,逻辑会更直观一些。(1)选中规则文档和需求文档:@你的测试用例规则文档@你的需求文档。

十二测试录 2437

关于OpenSessionInView的学习和使用

以下均为转贴1、说说为什么使用lazy 当使用Hibernate中的one-to-many、many-to one、many-to-many关系映射的时候,一个对象中会包含一个或多个Set来关联其他的对象。例如:user-groups,当程序取user 对象时,如果一个用户有多个自定义组,那么程序将把组的信息也读取出来,在log中可以看到两个sql的输出。但是在页面的显示上,也许并不需要显

燕窝 2159

java毕设:基于springboot的服装搭配推荐系统(springboot+layui+jq+html)1011

项目描述 基于springboot的服装搭配推荐系统: 基于天气服装搭配推荐系统为用户提供未来一周的天气预报情况,并根据预报天气和用户现有的服装进行着装搭配,以及显示未来6小时精确温度数据为用户提供更精确的天气信息便于用户在出行前对自己的着装进行调整,每日用户可以根据自己当日对系统推荐的着装搭配舒适度进行反馈,系统将根据用户的反馈对用户着装的保暖系数进行相应调整,通过多次的反馈和调整形成对用户着装的个体化和精确化的推荐。 本系统可以为用户提供以下服务: 1.未来五天的天气信息显示; 2.未来六小时内天气温度

qq_2537071370的博客 3648

OpenSessionInViewFilter的配置

今天上午在用到hibernate的一对多的时候,出现了hibernate的延迟加载的异常,以前都是直接配对lazy=“false”,没有用过OpenSessionInViewFilter,只是晚上在宿舍和几位室友聊天的时候,听他们提过。就想用下,结果还真的出现了些许的问题,值得写篇文章来记录下。首先自然是最web.xml中配置OpenSessionInViewFilter了,如下:没得说,网上一搜一堆的·······OpenSessionInViewFilterorg.springframework.orm

枫林晚【大音希声,大象无形】 1123

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

OpenSessionInViewFilter

 文章转载地址:http://hi.baidu.com/accpandsvse/blog/item/7e167783f271e8ab0cf4d297.html OpenSessionInViewFilter原理以及为什么要用OpenSessionInViewFilter  struts2 里面OpenSessionInViewFilter一定要写在最上面 下面有讲解--

我行我能 2327

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

OpenSessionInViewFilter详解

spring 的OpenSessionInViewFilter简介及源码 假设在你的应用中Hibernate是通过spring 来管理它的session.如果在你的应用中没有使用OpenSessionInViewFilter或者OpenSessionInViewIn

6137

OpenSessionInViewFilter 的配置及作用

Spring为我们解决Hibernate的Session的关闭与开启问题。 Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层,当 Web 层访问到那些需要延迟加载的数据时,由于加载领域对象的 Hibernate Session 已经

sunsea08的专栏 6万+

关于OpenSessionInViewFilter

<br />最近在参照项目实例学习Hibernate,Spring. 看到web.xml 当中都使用了OpenSessionInViewFilter,但是读书当中可能读了就很快过去了,没有留下印象,再google一下,查阅资料。网络上资料是如下解释这个filter的。<br />如果你的应用中hibernate是通过spring 来管理它的session,如果在你的应用中没有使用opensessioninviewfilter 或者 opensessioninviewinterceptor。session会在

rick_123的专栏 779

深入OpenSessionInViewFilter内幕

最近不知道干些什么好,无论做什么都觉得没劲,为了强迫自己学习,准备研究些开源项目的源码,从中找点乐趣,先来个大家熟悉的OpenSessionInViewFilter,下面我将逐步分析OpenSessionInViewFilter 的源码,了解OpenSessionInViewFilter 的原理,欣赏spring优雅的代码,本文只分析源码不做功能介绍,如果有朋友不熟悉OpenSessionInVi

孙钰佳的博客 1万+

由OpenSessionInViewFilter引起的No bean named 'sessionFactory' 异常

    今天在做一个项目时用到了OpenSessionInViewFilter,其作用不再复述,Google一下一大堆。项目在自己编写的java类中测试时正常,在tomcat中发布后启动时正常,但是一访问就抛出org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named sessionFactory

tianice的专栏 1万+

OpenSessionInViewFilter原理以及为什么要用OpenSessionInViewFilter

struts2 里面OpenSessionInViewFilter 一定要写在最上面 下面有讲解 --------------------------------------------------------------- 1、说说为什么使用lazy 当使用Hibernate中的one-to-many、many-to one、many-to-many关系映射的时候,一个对象中会包含一个或

刘书的IT博客 556

OpenSessionInViewFilter配置

最近在配置 Structs, Spring 和Hibernate整合的问题: 开启OpenSessionInViewFilter来阻止延迟加载的错误的时候抛出了这个异常:     org.springframework.dao.InvalidDataAccessApiUsageException错误 但是在我们开启OpenSessionInViewFilter这个过滤器的时候FlushMod

梅鹏同學的专栏 3402

OpenSessionInViewFilter详细介绍

Hibernate的Lazy初始化1:n关系时,你必须保证是在同一个Session内部使用这个关系集合,不然Hiernate将抛出例外。 另外,你不愿意你的DAO测试代码每次都打开关系Session,因此,我们一般会采用OpenSessionInView模式。 OpenSessionInViewFilter解决Web应用程序的问题 如果程序是在正常的Web程序中运行,那么Spring的...

西风禅林 142

OpenSessionInViewFilter 作用

Spring为我们解决最让人头痛的难题之一,Hibernate的Session的关闭与开启问题。 Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层,当 Web 层访问到那些需要延迟加载的数据时,由于加载领域对象的 Hibernate...

ayumi11112的专栏 142
上一篇: josn工具类
下一篇: axis webservice 的实现原理
oolala
博客等级 码龄20年 2粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值