 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
1 I7 c+ @: ^8 u, K- j基本参数:
' S+ c% U- ^7 G. R* ]jta | thread | managed | custom.Class
, H) q2 r2 |( A- J5 D: D: |* y主要是配合
( b9 |0 {; X8 Y" m9 z4 e0 fSessionFactory.getCurrentSession()
9 n! |3 z5 ^3 k来用的.
" w0 p: v' K$ A( T6 sThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 }) e- O) S' v* \: A! a% t# XWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
& _; {( Q" V0 w5 i2 wcontext.BeginRequest += OpenSession;
2 B+ a7 p9 k4 g2 j5 k4 a.Bind(HttpContext.Current, SessionFactory.OpenSession())* ^7 c( c0 I5 G1 ~" u" h& H7 u( P
2 |3 y C: c1 X/ Y4 B$ p//do transaction6 R" k! Q) F( x, ^3 i) Z
getCurrentSession().Submit();8 J' H ?& }9 D4 f# e% i
getCurrentSession().RollBack();
* V% Y+ x* {& @7 x/ Z v..., O; s) b2 |8 x1 v* q
Unbind(HttpContext.Current, SessionFactory)1 {! k. C, K# i; ^# c) Y7 N) p
9 [8 n ^# W. K& U! m) w0 }) f# A* X
context.EndRequest += CloseSession;
& j Q1 W* I( v) @9 {1 U% M3 } r: ~2 o: f2 b. q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|