 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
/ b! |. T3 R! x& W基本参数:9 m/ [. v' [# ~, L J
jta | thread | managed | custom.Class
# n0 b; f2 _1 s1 _" J主要是配合
# t+ ^1 E* Y) ]4 L' JSessionFactory.getCurrentSession()
: v ?$ k) V/ v. I来用的.
4 ]$ @& x* w/ m; }Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
5 x1 g7 Y$ K0 t- g& m" y( RWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:1 w+ Y! t: v% ]( d
context.BeginRequest += OpenSession;
# a, a9 { p( T. r4 B7 W% C/ h4 S.Bind(HttpContext.Current, SessionFactory.OpenSession()): u. |% L: i4 I, \) b' u3 f8 U8 t
5 ?+ ~0 w3 U) q: ]//do transaction
2 v4 T7 s! f i4 h3 {, BgetCurrentSession().Submit();! J+ O4 D* k4 H- n0 \9 ?) V! H8 Z6 \
getCurrentSession().RollBack();
! d3 n2 w& T! _+ }- g...6 v; { S: `; Z, [
Unbind(HttpContext.Current, SessionFactory)! d3 Q8 ]# ~, _5 c
! `7 i/ X# u" W7 Ncontext.EndRequest += CloseSession;7 r% l; N4 | N
- z4 W( i0 @3 d5 e0 v
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|