 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
$ d0 r4 i6 l+ J$ \+ m4 k5 a基本参数:4 v& g0 _+ O. y( z- S
jta | thread | managed | custom.Class
* m3 Q6 i' L8 A# U" r, b主要是配合
1 q4 d6 ]) s& n( dSessionFactory.getCurrentSession()
4 p- L1 {" X' u$ v来用的.
$ S; s: A6 |& F! c z4 K1 S5 SThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,* O0 A% S q( K- y& A
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:7 D+ J, D6 A1 k
context.BeginRequest += OpenSession;! H6 I! \- s: k- {
.Bind(HttpContext.Current, SessionFactory.OpenSession())$ D9 F* t0 E Q& m, W
0 i. @: f3 U/ {: m, N: q3 r
//do transaction/ j9 S9 B7 \# V s4 \
getCurrentSession().Submit();4 M0 L6 W: D% Y& f6 A' K* J. G% R* K
getCurrentSession().RollBack();9 c5 D4 D# R, \4 l
...0 w a: _. t2 |' k5 K
Unbind(HttpContext.Current, SessionFactory)1 B: [3 l( E! R" U4 J# U2 h
3 l# T: f6 W, s3 e/ E! l+ \
context.EndRequest += CloseSession;
! N$ ^. [2 n; F) F1 w; l5 A& ?' Q; {) o; G9 X) X- h
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|