 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what6 x' K4 a. p3 g$ T1 E
基本参数:
0 L+ j* @0 N. Z) C; _( e8 Q! ejta | thread | managed | custom.Class
# H5 h3 I7 r' _' [2 S8 L3 x9 d& W- Y主要是配合1 } f9 B ]' S) N' M6 [
SessionFactory.getCurrentSession()
/ ~- z" E+ I5 N# ~ w: i来用的.
5 h. f1 r& n3 U9 X6 O1 w; h$ WThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,6 Y7 i; o- f" C; B) | W
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:# K# d( z/ [+ g: W7 a
context.BeginRequest += OpenSession;7 N8 b" h" s9 L9 U" p5 d
.Bind(HttpContext.Current, SessionFactory.OpenSession())
; O% b, y, S8 v U( I$ {! {: R$ b( S w6 T
//do transaction" Z+ U8 l( t9 g5 v* z
getCurrentSession().Submit();
, F Q. g/ Y# W! O% bgetCurrentSession().RollBack();
* L: g$ {5 i8 ^) P/ [% Y...
; E* I- @) K3 r$ W3 D! VUnbind(HttpContext.Current, SessionFactory)
/ r0 ` A' M, J: H+ E* u! h& V0 C/ S; F# U& X5 j; m7 u) T: A
context.EndRequest += CloseSession;
4 N' I+ \) Q- g# y1 z1 t
& i3 |/ ?) W2 e! q" q 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|