 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what& F' ^7 S: i' }) ], V* H2 A
基本参数:. m m" |" A' Z; L) A/ M' X
jta | thread | managed | custom.Class0 J& h- U( r2 R* Z
主要是配合& k" r! v: v0 d( Q, V: K
SessionFactory.getCurrentSession()
3 l/ c. R- M: a- i! A+ X来用的.
8 O4 l3 l/ N" Q0 W. X9 QThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
$ H% i, X6 T7 R/ V. cWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
, @% o5 p) h( e* a `, e7 Jcontext.BeginRequest += OpenSession;
$ \* ^ a0 r! R1 `, P4 i9 I7 o.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 p" c3 D4 ^" C y2 s6 y: V' O6 l* m/ G0 C7 q! F+ P+ P9 g
//do transaction
6 E- B4 m; k0 M4 O2 h6 b' OgetCurrentSession().Submit();
; z' B( c o! ]$ L! GgetCurrentSession().RollBack();
' k9 k& G: p: k* D...# _+ z, t6 J: O
Unbind(HttpContext.Current, SessionFactory)
/ V; e: B/ A$ P3 N0 Y4 P7 ]: [% M, b5 i @( Y
context.EndRequest += CloseSession;
. P( t0 S* V+ W: s
- }# x/ W+ l, H% Y2 V 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|