 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
* c3 w& z. J& ~* d8 m1 J基本参数:
. D; W! Y7 F4 pjta | thread | managed | custom.Class; L! t. b; f/ m4 U
主要是配合
7 o2 w# r! h7 C s3 fSessionFactory.getCurrentSession()2 n0 { s: `/ M) H L
来用的.0 _' e- D+ {+ j" M
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
& e3 T! F3 V' s3 l0 y9 q* Y NWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:- a+ H5 R3 K& `0 E
context.BeginRequest += OpenSession;6 z2 T; ~% s/ X
.Bind(HttpContext.Current, SessionFactory.OpenSession())# q- E P, q( R y# C
3 b+ G9 }/ P% r) O$ S" B% G j
//do transaction6 b/ `" }! b7 [+ \" X# \
getCurrentSession().Submit();+ [' W: c) E f% p8 w" M
getCurrentSession().RollBack();4 u6 ~$ N; n5 `3 p8 x
...; O+ Q3 a7 E9 o
Unbind(HttpContext.Current, SessionFactory)
1 L& g5 O, a0 d5 N- R3 x* J% m5 i
0 \) ?. z7 e# |) i+ a- m# b4 x4 gcontext.EndRequest += CloseSession;
4 }: Z) |4 q, T6 {
9 Z6 U$ W) E1 z7 ?+ a 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|