 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
2 \6 j4 P* Y- u! D! u基本参数:6 R. ^" {" Y# Q8 b
jta | thread | managed | custom.Class; y! ^, P5 P# ?
主要是配合
m4 ^0 u4 } g6 }: V6 E, SSessionFactory.getCurrentSession()' U3 d+ Q: n2 e/ K. ]
来用的.
9 x; `8 q- y0 r5 R1 _+ Z3 l. C" d7 ?Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
0 F5 R, I/ }7 k9 Y# U F: n3 PWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
# b& a+ I" }% p8 a) B* I6 [context.BeginRequest += OpenSession;
9 d, M U! G% A l J) U/ r.Bind(HttpContext.Current, SessionFactory.OpenSession())$ E# N; a5 M {: n* P
4 i' |: m1 R3 Y) ~. D7 U//do transaction
+ @+ W& e: {6 x+ e4 }getCurrentSession().Submit();
1 K2 A9 y5 f8 h% e$ j: I& xgetCurrentSession().RollBack();
( W8 D4 A& n$ Y1 m! e. l...! b, P, a; o8 d, B* m
Unbind(HttpContext.Current, SessionFactory)
, f) J5 v8 z: C" T q
" [& Z2 o. n7 c0 {& r0 acontext.EndRequest += CloseSession;
3 x3 \$ P( v, z7 O( Y
& _0 m& j+ z6 Z9 \/ X+ \( e7 ^8 n0 O 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|