 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
& ~! l5 B+ g" [4 M; b基本参数:
8 f" O$ o2 p+ R/ v0 Hjta | thread | managed | custom.Class
1 c% Q, p$ i/ w- u0 G0 t0 E主要是配合5 A; Q" s. X1 p$ _7 ]
SessionFactory.getCurrentSession()
7 H8 ^8 i: `1 |4 R9 y; l来用的.% y1 p/ ?) Q% c9 Q8 l
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
; z: a' f- }, r x# b. d! SWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
" ?# q' X4 F: B+ ^context.BeginRequest += OpenSession;
: G- P! |( E# F" ^ o* [.Bind(HttpContext.Current, SessionFactory.OpenSession())
2 f" U" L( \ Y" E" \% `+ s- D% u0 w! ~
//do transaction4 g) F5 e, ], A
getCurrentSession().Submit();
e- v' m8 S4 N# _getCurrentSession().RollBack();
' X+ P5 H8 `0 X2 |7 B8 k...
9 i( n5 g8 w" s$ GUnbind(HttpContext.Current, SessionFactory)
- v9 N+ _$ T J' S \! c5 I* U: u5 o( n1 P$ K$ H
context.EndRequest += CloseSession;) Z& D! D0 ^( V5 S' q% |
% L( p3 u. K. b2 J2 A
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|