 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
6 o7 W) F8 X/ T- v& F& s5 N基本参数:
! F- O8 ]- ~- Njta | thread | managed | custom.Class; N6 h! J% w, H' J
主要是配合5 Y1 u- T3 @. u y
SessionFactory.getCurrentSession()% J( M5 r' _# }! D2 z' f
来用的.* a% b \; [* U3 _- B
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
( b" o/ [7 ~, F+ W* r7 lWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:6 V6 f& \, @, |: c
context.BeginRequest += OpenSession;
; n$ s! Q2 Z6 s* b4 \.Bind(HttpContext.Current, SessionFactory.OpenSession())
t v4 f! H' D% I" z; O6 Q" L' D' h7 Z F1 F- D* U
//do transaction# h3 S6 d" `0 z/ Y7 v# m
getCurrentSession().Submit();
$ t2 `5 p3 Y, cgetCurrentSession().RollBack();4 E' w+ i' W1 O! w- N
...
% S- I9 ~( }) s; q+ J! p8 G; ?Unbind(HttpContext.Current, SessionFactory)3 v @6 q+ F6 h
/ Z I, g7 C4 e- R: N8 a+ R
context.EndRequest += CloseSession;
' g+ ^# G$ q( Y) I
! \$ U& K1 \3 W6 x3 n0 m 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|