 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what0 S- e3 h! c9 j$ Q( n4 }
基本参数:" I7 H, ~5 k0 b; {- H
jta | thread | managed | custom.Class( }( e2 K2 h+ ?$ r; }. f- N
主要是配合2 j: K# B$ j( T- z- l8 ]( [
SessionFactory.getCurrentSession()8 L1 y' Q$ M! E* p5 B9 J% X
来用的.
/ [5 s. ?" E# k4 ^4 G% R& I2 mThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 D" p6 Z C V1 |) k E) NWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
, P" h% k) B0 ~# `context.BeginRequest += OpenSession;; F! z( q* ^" v
.Bind(HttpContext.Current, SessionFactory.OpenSession())+ b' N8 m: ?) }5 ]
/ _' k+ z) i) k* q2 E! Y, s//do transaction l% |" z, w7 n. a5 J8 z$ x
getCurrentSession().Submit();: D2 c& ]) a" Z4 E$ i) d
getCurrentSession().RollBack();
) V \0 I1 k! c' R. ~...
) Y2 l; _/ Y' F$ g6 H# \8 C \Unbind(HttpContext.Current, SessionFactory)5 I+ F2 W; Z {8 Y0 K
6 r6 d) `. ~% U
context.EndRequest += CloseSession;
. T. J- O" Z5 D! v; L/ F$ h6 j# D, \/ b B
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|