博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Do NOT hold static session in nhibernate
阅读量:6932 次
发布时间:2019-06-27

本文共 944 字,大约阅读时间需要 3 分钟。

Refer to

Every data access strategy after server-side cursors has had as a goal minimizing the length of time an application holds open a connection, and NHibernate is no different. Therefore, having a static Session sitting around open and available is a poor strategy.

Instead, you can use disconnected Sessions. You can still create a shared Session object (either instance-available or truly static) for use in your methods. However, instead of leaving it open, or closing it in every method, you can follow the following pattern:

public IList getClasses(){IList classes = null;try{  // session is declared in instance scope  session.Reconnect();  ITransaction tx = session.BeginTransaction();  classes = session.CreateCriteria(  typeof(UniversityClass)).List();}catch (Exception ex){  // handle exception}finally{  session.Flush();  session.Disconnect();}return classes;}

转载于:https://www.cnblogs.com/webglcn/archive/2012/09/06/2673000.html

你可能感兴趣的文章
[MST] Build Forms with React to Edit mobx-state-tree Models
查看>>
logstash 自动重新加载配置
查看>>
装系统w7、ubuntu、centos等系统(一)
查看>>
spring-boot-mybatis
查看>>
【问题解决】连接mysql 8错误:authentication plugin 'caching_sha2_password
查看>>
Jenkins使用遇到的问题总结
查看>>
Python从菜鸟到高手(2):清空Python控制台
查看>>
几道有意思的逻辑分析题
查看>>
Cracking the coding interview--Q1.2
查看>>
Permission denied: user=root, access=WRITE, inode="/":hadoopuser:supergroup:drwxr-xr-x
查看>>
p-unit - 单元级别开源性能测试框架
查看>>
WinForm 实现两个容器之间控件的拖动及排列(图文)
查看>>
C/C++版数据结构之链表<三>
查看>>
CentOS下实现postgresql开机自启动
查看>>
libxml解析的attributes参数理解
查看>>
VK Cup 2012 Qualification Round 1 E. Phone Talks
查看>>
volcanol_Linux_问题汇总系列_1_系统引导过程中到check filesystem时就无法继续引导问题解决方法。...
查看>>
XP局域网访问无权限、不能互相访问问题的完整解决方案
查看>>
使用xml布局菜单
查看>>
我的大学四年
查看>>