 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
' o9 y' O. F. ]' S: U9 h基本参数:
9 {+ I: u( E" b1 f: a4 kjta | thread | managed | custom.Class
/ ^1 s9 x9 k I6 s8 w6 U0 r主要是配合. p! k! U4 O/ w0 \! K- L
SessionFactory.getCurrentSession()
4 M! x6 y; p5 N# @; S) [1 G来用的.
# o: C0 F, X3 g4 S. z2 uThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
* B( s8 W8 t5 G! R, J$ oWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 V" Y7 u, B4 F
context.BeginRequest += OpenSession;" x$ i% }" t' J) \' j
.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 w' J) i/ F i0 G" H5 k
+ R2 m0 C# }# X( C. \$ i1 O: N# z//do transaction- b1 c7 s! a" `" v- s2 }
getCurrentSession().Submit();
. e5 K8 z. r7 C1 _! f: I0 C4 PgetCurrentSession().RollBack();9 T, X; a6 o; ^1 B7 Q
...
$ \/ ~3 q/ ?! j# J' r/ i4 O. V2 dUnbind(HttpContext.Current, SessionFactory)
& E# U# a. f% I7 j$ U
' r% S5 W L# g5 f1 ccontext.EndRequest += CloseSession;# d* i3 r( ]* E+ `7 @- z
6 q, W- z7 y: } a
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|