 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what, I9 g7 M+ d0 ?2 a. K& f
基本参数:, h# G1 E/ f$ W, T$ l% U" i0 }
jta | thread | managed | custom.Class
2 W+ S( R; r3 y% B7 F* v) A) M主要是配合. B+ u& W8 s- ^4 d
SessionFactory.getCurrentSession()* L, l+ R. V0 o5 l
来用的.
m. u/ y F/ g! \1 gThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ O {& ]) t7 n3 y
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:: a# V" ^. j w% h& z% R9 L
context.BeginRequest += OpenSession;( |' }# X( o6 X* z8 H
.Bind(HttpContext.Current, SessionFactory.OpenSession())4 B% c: W( m% L% O8 |: |* }' b
) g: X/ F' U* Z//do transaction1 M7 c/ D: O. s6 A3 N! w0 t0 c
getCurrentSession().Submit();
9 t i0 m' K# c X6 M+ sgetCurrentSession().RollBack(); ?% p3 v( B: y& g/ e$ a! S
...
1 Y4 {! b; {& G: lUnbind(HttpContext.Current, SessionFactory)0 ^0 S3 j# W D/ r( T5 V
+ I3 }7 v6 V; `( a/ C2 m1 n# gcontext.EndRequest += CloseSession;
" U U6 P9 f" I, D% u9 D$ R {- r7 O/ c- e
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|