 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what9 u- `1 v9 y! K+ L- Y
基本参数:
1 y$ B- ]2 }: I, mjta | thread | managed | custom.Class2 Y' `( t5 X$ ^7 |9 q2 w
主要是配合: j" n: ]/ n2 f* X2 B+ c3 @
SessionFactory.getCurrentSession()$ P1 U1 B. L! ?* f8 x7 w2 e0 d4 P
来用的.
$ c9 ]1 N$ v0 v8 j/ _: @Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 O4 t4 m" u3 H' X, AWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
' K& i! y$ @5 E6 ]# `context.BeginRequest += OpenSession;4 S) B; Q5 {2 A6 e; M
.Bind(HttpContext.Current, SessionFactory.OpenSession())$ O" F% H# z v; T
# j5 _" s3 g5 k: a' K//do transaction3 M" F6 E6 n: ]0 N9 D
getCurrentSession().Submit();
4 Z# M$ ^! L+ [getCurrentSession().RollBack();* X2 a8 j* J. V
...% M8 \8 ], i' l( a6 M% e
Unbind(HttpContext.Current, SessionFactory)$ s* V4 B# H1 o/ W( A# ~
$ n6 I/ w7 n/ w* C) x1 {; acontext.EndRequest += CloseSession;) E$ \5 B1 w" R g; S3 Y9 q
2 H1 l$ k4 U% c Z5 I+ A0 @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|