 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
( b6 p* H, q5 w" S g: d8 \2 h6 q基本参数:+ y0 L& _6 @$ _6 V% J
jta | thread | managed | custom.Class+ L, a0 B7 @1 p
主要是配合4 ^$ C; ~4 F" Z! G
SessionFactory.getCurrentSession()0 r* }6 T4 t0 _8 H
来用的.
! h- x h- z, h1 E: h0 N7 ]Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 }7 r0 [" X4 pWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
* t; b& V# H$ k8 Ccontext.BeginRequest += OpenSession;7 w0 V0 k! D Q6 U2 C b7 I7 g
.Bind(HttpContext.Current, SessionFactory.OpenSession())
3 j. q# Z! C9 o5 ~" @( _! {/ |# ^/ r _7 J& V
//do transaction
# n9 o3 e2 j& |7 b; LgetCurrentSession().Submit();
) b) a8 b# P% X0 z9 XgetCurrentSession().RollBack();
! r! h, |7 y; s" \& V' M...
( h" y- o/ Q8 D5 CUnbind(HttpContext.Current, SessionFactory)
! @; P- i: K5 b, d0 \
( j( o3 y' k l, {! G, m* {context.EndRequest += CloseSession;8 \. q1 E- e6 I4 t d2 e
( S/ u. W+ |1 I6 e0 G8 Z/ k$ S, ~ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|