埃德蒙顿华人社区-Edmonton China

 找回密码
 注册
查看: 827|回复: 4

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
$ r* y: U  P9 A2 |" F9 C
- s9 r4 z" b  }7 E$ Z7 k& ^谢谢1 M/ v. U  O/ h/ g4 b: R! K0 W
' b; ^: m$ ~/ u0 X8 ^: A! `
<property name="current_session_context_class">web</property>
$ `9 T8 D; A7 O# A1 P6 r<property name="current_session_context_class">call</property>
1 O! |, f* H! ^9 d0 }$ U<property name="current_session_context_class">Thread_static</property>
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 20:52 | 显示全部楼层
自己顶一下,等高手出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-14 20:56 | 显示全部楼层
本帖最后由 gamahu 于 2011-7-14 22:47 编辑
$ ?4 K9 B  a5 [2 ?7 _
9 l. J  C/ o9 x  `Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
% m! G& k0 d) t+ j9 o: i. W8 i0 A- s2 p
% Q1 N0 d* N1 r
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf3 Y3 t& K3 ^: B  Y' `* h

- M0 v( _/ y1 O) v. [$ U
3 c# U3 M+ @. v2 W! |. i0 _. PChapter 2.5 Contextual Sessions) L6 J( S( C  H+ z. {  Z6 M
gamahu 发表于 2011-7-14 21:56
3 c" P" G$ O6 _/ p- R3 J, ^
* {: g' Q9 E  A; e! R
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
5 @7 k3 F0 N( Q2 f2 V8 |* J- i' i8 W1 ]
现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what
9 ~( h9 [8 h" ]  X基本参数:9 L9 O7 O6 B  `" d
jta | thread | managed | custom.Class8 }1 ]8 |$ [& Y7 A( \
主要是配合
/ U# O& p9 U; T- u: f) [$ f/ DSessionFactory.getCurrentSession()  l' E% b8 H6 y& K
来用的.
# q- T. Z# P& GThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 f' i; k$ N+ H! xWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:; B: _. ]2 @' p2 c9 ?9 Y; ]
context.BeginRequest += OpenSession;
9 k* n+ m& h% O+ r.Bind(HttpContext.Current, SessionFactory.OpenSession()); O( p; h; c! ^- q0 M+ W: p
- ?% w( D7 `" B$ G& c7 Z/ G
//do transaction
7 |. V1 p' V0 a1 Z9 c  z$ y. HgetCurrentSession().Submit();
5 q  t! ?" y, q. I* |getCurrentSession().RollBack();9 X* d4 y8 L7 I2 R- D
..." [0 }2 \8 {' ]* b5 F& ~
Unbind(HttpContext.Current, SessionFactory)
  s% K) t1 S- ~
! l2 Y( l# R, a; G4 o5 ?context.EndRequest += CloseSession;
, Y' j& H. H, T  {% K, G1 \7 m0 O5 U& ^- R8 [
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
理袁律师事务所
您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系我们|小黑屋|手机版|Archiver|埃德蒙顿中文网

GMT-7, 2025-11-17 19:18 , Processed in 0.194439 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表