 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what. u6 J4 P) V6 c$ b* t
基本参数:
) n/ R+ v! |6 m/ o" A+ @7 x. xjta | thread | managed | custom.Class/ P2 {$ Z+ J; N8 r$ ^ O
主要是配合
; A+ a1 k2 ?) c8 g5 E) L! j% GSessionFactory.getCurrentSession()
+ ~4 m4 C* b4 \, u/ S1 p& L来用的.
`% a# J! X! r9 M$ f" vThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 } f3 b8 x% U/ ?" ~0 EWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:7 X2 D$ o$ N# W5 k- p8 {4 ~% Z
context.BeginRequest += OpenSession;. w4 d3 q5 {" Z# K0 b' N* ]
.Bind(HttpContext.Current, SessionFactory.OpenSession())" l! }; Q- N8 d# A4 G3 a
' b% M8 l7 ^. T
//do transaction
. g* X! n$ U: O+ f, {getCurrentSession().Submit();) S; F0 g- q9 ?7 w' M
getCurrentSession().RollBack();) J( g( j7 l" n. ?! B
...
( K7 k) C( E+ r1 cUnbind(HttpContext.Current, SessionFactory)
6 T: r0 Z0 V% J9 U$ Q9 L8 {8 ?
3 f' ~2 V) \1 G4 Ycontext.EndRequest += CloseSession;6 k2 I: \# C- J, w# o5 ]2 w& a
1 t" v+ N# U( k4 J: j1 ]# }2 j9 c, q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|