 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
+ t3 D) j! L/ X9 L& N基本参数:
, [5 Z$ e9 W/ l4 E: t7 jjta | thread | managed | custom.Class8 @+ r s5 |5 m
主要是配合
5 c& R6 R+ o5 w* C6 R. QSessionFactory.getCurrentSession()0 }( A# C% Q* m S$ o
来用的.
& \4 d1 a- J/ hThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 m# q2 r7 q" b6 q9 J4 mWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
# g2 q( j! e. l2 e; Bcontext.BeginRequest += OpenSession;
6 n9 l' f0 p+ V8 Y.Bind(HttpContext.Current, SessionFactory.OpenSession())
8 s6 E P! X1 s+ x6 y Q0 K4 }/ c2 G! b" ^% ^0 A- A
//do transaction \% a8 y; Y6 p6 u6 t
getCurrentSession().Submit();! O {0 F+ Q$ y$ T' q
getCurrentSession().RollBack();
5 A: w# ^6 R7 W5 a( E T...8 ^0 u0 f# S5 K) x& f
Unbind(HttpContext.Current, SessionFactory)0 f4 Z# V, Y7 }
/ L# g0 ]# Z7 U0 E; S' ^* S
context.EndRequest += CloseSession;4 [7 K9 V2 e0 I6 Z5 b8 V+ J, U
8 W) b& m I; I- a6 N, m. Z% f! q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|