埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?/ E8 E/ }: ?: y: J
( f* x* x( C- Y  l- L+ ]% v$ U
谢谢8 `0 h$ E, P' a( i& W9 E
  v+ g8 Z5 u4 y
<property name="current_session_context_class">web</property>
; W- l2 s5 f4 D% e6 n6 N<property name="current_session_context_class">call</property>6 P' B! G  w. l2 e6 {- t% g, P. l& @+ R: ~
<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 编辑 ( f: m) Q9 l7 K; V+ }1 z
# m- C; X: `2 S
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
9 g) y: \; y6 g% W0 c9 X' g. `4 X
7 b2 ~8 z9 t. b6 s. m3 }
( e5 ^. b$ e; \8 h7 M8 W7 x6 DChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
7 A9 D7 r! m0 q. N
4 ^1 w/ |4 b( t- d! S3 T. K2 @1 a/ s# V
Chapter 2.5 Contextual Sessions" G! @4 s0 R! K( y! B# m
gamahu 发表于 2011-7-14 21:56

- ^" Z- U* S+ m; p  I
0 M' k% ~, O3 z' n8 k. Z谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
2 P, s2 x2 {2 N2 B! }. k/ v& W; b, c  r3 G3 F
现在还多了个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
4 X& m6 K& q4 b7 q  R基本参数:
0 Q5 |/ o: Q0 ~6 Y" t. H2 [) y8 m8 Ejta | thread | managed | custom.Class0 S" @. O8 @+ |
主要是配合$ V( S& X" T* t) M& X
SessionFactory.getCurrentSession()* G, }# x- `. a% x/ Z. _
来用的.
1 S. a3 S" D( mThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,3 Q6 x1 u' V5 |2 K
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
" h+ p" u; k" Z$ n7 V9 S3 ?context.BeginRequest += OpenSession;7 p+ t7 T3 O2 N/ r/ w
.Bind(HttpContext.Current, SessionFactory.OpenSession())
7 P. g& f: g% {8 {( K' U( }7 {( B6 l8 u: M
//do transaction1 p& G' u! M* S) m" s' ~  s7 Y
getCurrentSession().Submit();
4 |8 |% w: K) B3 I) d, o, x2 F% BgetCurrentSession().RollBack();
$ e! ^9 f2 a+ N( a3 P+ ]% l" n...4 e; G; Y. z2 l5 F
Unbind(HttpContext.Current, SessionFactory)" H& l' u# V8 x9 H* W9 C

$ @- ]/ p6 V% J8 dcontext.EndRequest += CloseSession;
+ c$ c( I0 f( l# X) g" W4 f) W) `2 {6 _' N/ Z8 V5 M
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-17 14:07 , Processed in 0.094117 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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