 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what2 Q' A) h! f* Q \
基本参数:$ j# O4 J( ^$ ?" S. t% d$ Y
jta | thread | managed | custom.Class$ ]7 B! f, a; ?3 U; `
主要是配合
* }' M6 _4 `+ F0 v. }SessionFactory.getCurrentSession()
4 X1 G% u9 Q! o$ R来用的.
% J, x% Z4 e$ u* Z% RThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," Z% l! v1 t4 I' ^" u' M1 O( A
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:3 n8 a& M# l6 o
context.BeginRequest += OpenSession;
, v* @' V6 ?0 F2 G% z" g8 O! e! }+ c.Bind(HttpContext.Current, SessionFactory.OpenSession()): o1 R6 Y+ t3 Z( ^* S, @& ~6 X
$ w6 S4 d4 G5 y//do transaction8 i+ [6 J0 p* }4 B/ K1 B" v3 }
getCurrentSession().Submit();
* a0 y1 a1 c/ H9 q! Q9 G, |: }getCurrentSession().RollBack();
, e: U% N) l8 m/ n; F7 c...
3 w- w% \7 e, b' ]) [) ^9 S: ]Unbind(HttpContext.Current, SessionFactory)( }2 t' a& |; ~. O
7 m( R3 _+ R- K# @7 ? m
context.EndRequest += CloseSession;
% G8 d1 \* s: P
3 L5 N" T9 r2 l+ H! v) m/ d 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|