 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what9 i; M% ]# X1 V* D7 y
基本参数:4 T4 H! H, R1 v5 {9 i; w: ?. I
jta | thread | managed | custom.Class7 M3 z2 M; A# I0 n: Q6 ]
主要是配合* z9 I9 @/ ]7 c4 W& J8 K
SessionFactory.getCurrentSession()5 |5 e. v, w$ C0 o( t" G+ Y2 H
来用的.0 |, Y6 a2 j4 ?( @
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
; v4 o3 y2 k& I# I" vWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:: f% t4 y3 `) o
context.BeginRequest += OpenSession;
2 s# F: c! \# ^+ Q2 R7 X7 B; M.Bind(HttpContext.Current, SessionFactory.OpenSession())
L2 L9 Y8 g1 B, X7 j. N4 F! z' F7 v
//do transaction( Y9 E+ t& b( q' c9 v% z8 ?' b1 P0 e
getCurrentSession().Submit();" Z1 ~" j9 l: T4 m) f! V h* p! {
getCurrentSession().RollBack();
9 n7 `3 t1 P& |6 b/ ?% }...
" v+ i1 f- Z' C6 b$ dUnbind(HttpContext.Current, SessionFactory). `: t! U+ F7 m
" d$ r# S+ v* s, R# l7 A$ ^
context.EndRequest += CloseSession;
7 R& j4 B( z% ? q; L$ s9 W( M i' q% k# }
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|