 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
4 |$ X, z3 [* H, u* ?基本参数:+ Y. h) ~) J* i8 x) A
jta | thread | managed | custom.Class, T2 _$ ^$ I5 I1 H! i6 L4 w' O% [" }
主要是配合9 @( j* ^, t7 I! a$ ]$ M9 {! {! V
SessionFactory.getCurrentSession()
! e, a' M# G% r来用的.
& e$ |. u/ u# h& Y& ^# y! mThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,0 a+ @5 T; z. P( F
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:; _0 }4 q" S# \5 L+ s8 L
context.BeginRequest += OpenSession;
# P+ Y1 d5 ^! K- X# e( v: Q.Bind(HttpContext.Current, SessionFactory.OpenSession())
) w5 p) e/ V6 O& A
- j& v* V: w8 r5 T( W0 f//do transaction! g! _! f/ p* ^" B' u' w+ N' g
getCurrentSession().Submit();1 v$ e5 T1 C9 r" f
getCurrentSession().RollBack();) T( j( D( k, X& L! _
...3 Q$ x" e- L( V8 H$ O; F
Unbind(HttpContext.Current, SessionFactory)
+ g2 t7 _$ c& i8 m- o0 w8 j( c
: e2 [$ C, u& ^& R8 n1 J' V" ^context.EndRequest += CloseSession;
s( e" D: V) m, G2 B2 ?5 b- M% Q# L3 t2 l- O3 f0 S) B
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|