 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
( p! T5 ~- P. }& x; w( h. X基本参数:% ~3 G( Q$ Z3 _8 h. Y/ c' r
jta | thread | managed | custom.Class" }+ I! o; X; D( _! f
主要是配合2 b! d$ k [- h2 `% A
SessionFactory.getCurrentSession(). y+ [' t/ d& b, u; L) t
来用的.
* h! a, u5 I3 {% FThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,% D+ j9 ]* ~3 a; l
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:" s3 R( @4 W+ |% r- A+ p$ F( Q
context.BeginRequest += OpenSession;
2 ?7 @5 f6 v! L, T+ a7 \. i.Bind(HttpContext.Current, SessionFactory.OpenSession())! Y8 V2 Z# f3 P* n; N* B6 K; O
% l' V" }3 C7 P6 q' i3 S7 u }
//do transaction
; P, R2 E) k: G! A( `$ p; zgetCurrentSession().Submit();0 k/ a2 x* |4 v8 G
getCurrentSession().RollBack();
1 {2 Q9 y8 W4 x: l! Z...: ?# T/ D2 o' H& j4 f
Unbind(HttpContext.Current, SessionFactory)
: G8 K' ?: G: C( ~+ T4 z6 s8 C; b
context.EndRequest += CloseSession;8 d' X' g! v: `
: O8 T5 x8 V) }7 R% L
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|