 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what& R6 }" G8 `0 v% s
基本参数:7 z. A! g3 w" I* `$ v" w6 A, F' _/ C
jta | thread | managed | custom.Class! t! H( i+ K$ V1 r3 Y
主要是配合
% D, z+ i2 }7 B) eSessionFactory.getCurrentSession()- L' X) H4 U7 U$ E9 P% S$ G
来用的.7 h4 s" J) g" D: {- y+ p# H
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," `* V$ i) h3 }8 P4 b J
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
% n/ J' b0 P( l, `* o- ^% Wcontext.BeginRequest += OpenSession;5 Y+ ^* T1 @+ L6 ~ H8 O* B1 _4 p
.Bind(HttpContext.Current, SessionFactory.OpenSession())* v- {- l. w. F7 e
, M, a' z+ a, C+ T# ?* q+ E
//do transaction
4 T, C9 |, t7 X" pgetCurrentSession().Submit();
2 e/ @" V( w% P. e3 ]& sgetCurrentSession().RollBack();& d9 Q0 H) D- I" H& T
...
" z% c' d5 N% A4 u) h% @; N" ~: \Unbind(HttpContext.Current, SessionFactory)( x. N4 V, k, L0 ^# K9 s7 M6 _* k
9 S6 g* g2 t. g+ |1 O% Ycontext.EndRequest += CloseSession;
; g n( D4 r s& {+ g, I# h$ l4 V* U' j2 i
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|