埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?( e5 a1 J, s6 T

3 z5 \- @2 ]6 {% h谢谢
% R& C; n) r! r2 j& `' G
' g. _' U& ^# f3 G* Q, h<property name="current_session_context_class">web</property>
/ O* C7 Z5 s- C<property name="current_session_context_class">call</property>+ h+ e2 t8 p. P
<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 编辑
! v. {  `6 J! l* N5 h# i8 U; p0 X4 U0 f7 t
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf. H) o& x$ D5 v8 Y$ b0 o- L

  N4 ]+ g  u2 e3 ^8 P6 r8 E  N. t0 y) C; p+ {5 t  _& v' M
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
) b. i" w! D% j) ^. F9 T7 Z. z: n- P! n: t
' i; G% A) P# I, h- o  D
Chapter 2.5 Contextual Sessions$ M6 r1 x' y( a- J
gamahu 发表于 2011-7-14 21:56

; O* V( D. Z. }+ S) B0 I. C  @; f8 b/ \1 P& Y8 [
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.( v, U4 V- K, U% q7 V) L. `
) P3 H  \% V( k! T3 M# I
现在还多了个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
! Y% R7 W3 e. N6 C- y基本参数:
8 }. W1 ^0 F4 a. ?1 J, y. D- w# fjta | thread | managed | custom.Class3 Z7 w1 E: g8 r5 x5 P  {0 e
主要是配合
6 q$ N( Q! m& h6 F: kSessionFactory.getCurrentSession()- V* X+ y" J7 n. _( `+ C* C
来用的.
$ X4 j+ f9 t# s- y. D+ V  d- cThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
: j, j# ^2 C# A+ u  _2 }Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
1 e) T' D- T, {) q$ x0 ^; D/ Ycontext.BeginRequest += OpenSession;+ g3 v# t( B4 _! q  r# b6 K
.Bind(HttpContext.Current, SessionFactory.OpenSession())
! \5 ~" @7 h+ }
$ f$ A4 S3 F* X1 n//do transaction
8 G3 Y7 t4 h1 L# K1 QgetCurrentSession().Submit();
( Q# B1 \+ ]/ \- L7 ~7 N9 i3 xgetCurrentSession().RollBack();" j; r) G# M6 v) {8 l+ k; k4 ~. v! ^
...- \9 g& T! l- u
Unbind(HttpContext.Current, SessionFactory)" e. T* j% \. S: ?& P& Y. [
7 ~" e/ y, p3 c% K# Z. n- a  T& t
context.EndRequest += CloseSession;
7 x1 E$ @8 k& L- q" B$ n+ a
% I" h, W6 l0 X1 i( v8 Q 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-23 21:10 , Processed in 0.150431 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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