 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what. R; ~4 R4 o8 V% Q
基本参数:
" N6 R: p( \# y( i8 u6 ^+ M( Yjta | thread | managed | custom.Class; a1 @* U$ C8 j& j
主要是配合
8 F6 f8 K! l( V# YSessionFactory.getCurrentSession()
( d: Z( ?* c0 {: [4 Y来用的.
7 T- q0 ~' E! E) `' wThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
F" H# F- f' Q' B( lWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 j! |3 O/ I, }: N: y# Hcontext.BeginRequest += OpenSession;
. e- c5 A7 W6 E: o+ r7 g( u# O.Bind(HttpContext.Current, SessionFactory.OpenSession())
" r' {6 D5 y" t, {% j
' P9 W3 z) P" ~/ ]5 i! z3 b1 @//do transaction
) g0 C* q' h1 |) B) _getCurrentSession().Submit();! H: F) k5 b3 B- `* h/ q) e2 H, b
getCurrentSession().RollBack();
! V* R3 J: D1 I$ D3 f+ B% s...
% l! P* b! x) IUnbind(HttpContext.Current, SessionFactory)* `# y- t- @* A0 U' a o
6 f- \- o# _. l6 k$ x( x" X7 J+ v) _, `: G
context.EndRequest += CloseSession;
0 V4 O" B* W* t. ~) m. g
- p0 M: d8 v+ B: f 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|