 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what* L2 [; f$ z/ X- A c# k
基本参数:. k0 \ k. h, e5 f8 {' }
jta | thread | managed | custom.Class3 F# z: _$ H, `' i1 }( p+ N
主要是配合
. F W7 z* r( t: x; G( vSessionFactory.getCurrentSession()
- S, w7 T) J* h! h来用的.
4 p! i9 p4 b6 S! QThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
, H# Z, _3 @1 Q" J, n) X7 ]% r/ dWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
- H6 m' a9 H; }7 Icontext.BeginRequest += OpenSession;0 T1 l9 l4 Y. O) B/ d7 c
.Bind(HttpContext.Current, SessionFactory.OpenSession())
: F2 Y) m) x) e" o, L( ~3 C2 B, a6 a- k. q! V
//do transaction
/ w. N+ o# K6 B3 SgetCurrentSession().Submit();
7 c6 b2 G. N% ^getCurrentSession().RollBack();
7 J: c1 x2 F/ u$ M' ~0 q...% F1 g0 J7 i4 Z/ r |+ r2 U. v
Unbind(HttpContext.Current, SessionFactory)! r; f( w$ H5 H' W T" S1 ?/ i1 @
( R; J8 [; _( C. d, {. V" Q
context.EndRequest += CloseSession;6 P9 k% U# I8 f2 Y
3 q9 K) Q9 i* N* ? 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|