 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
9 F1 b. x% u2 v& @+ B基本参数:) t/ D- c; m5 O% d
jta | thread | managed | custom.Class5 R: E m2 E4 B2 ~4 j/ n8 j
主要是配合5 n" c6 h2 d f
SessionFactory.getCurrentSession()
* M- }2 N1 t5 L3 L来用的.
- m) D* R$ ]* z# w4 G3 t! gThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
+ y5 f; I5 b8 K; gWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:) ^& [7 [2 y* x6 M: a/ {/ v
context.BeginRequest += OpenSession;7 C$ |! R) p* q1 ]
.Bind(HttpContext.Current, SessionFactory.OpenSession())
: r' [8 }. \! L' u% |0 l3 v7 A) ~3 {2 h( N
//do transaction
" i9 W7 l' u; o# NgetCurrentSession().Submit();
5 g" O6 Y& f) e0 G$ ogetCurrentSession().RollBack();
5 [! n1 a. z9 E% ^ d B9 `...
3 j$ J. D2 A, f; A0 d2 S* UUnbind(HttpContext.Current, SessionFactory)) C7 q% E. z2 K6 B- z$ Y8 |
" m" _9 n, x7 ]context.EndRequest += CloseSession;2 ?; q; p- j% r. b' u" O
7 S# F7 a8 c4 M# N. x
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|