 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
5 x1 _# f* `0 c2 X5 i+ [. A' G- ~基本参数:1 S% z" x2 v4 W: {% n/ v
jta | thread | managed | custom.Class
- q% p5 m* U* n2 f6 E2 b7 t主要是配合$ ~: S; w1 z0 h U6 U8 T y" K
SessionFactory.getCurrentSession()
: G0 y, ^1 a# U8 c! k# e, C# [来用的.) e; L% y) o$ g+ B f2 l# A. H8 q
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 ^8 x1 q; o4 |( r* H: Y7 E* GWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
1 v ]* Q7 Q1 G# ?context.BeginRequest += OpenSession;. e. R. D& f5 C9 D
.Bind(HttpContext.Current, SessionFactory.OpenSession())7 y8 ?7 Z3 \/ r' z I1 ^4 i' C
, s+ e- L9 m$ [+ B$ o//do transaction
9 A) Y# M4 Q( f, t( z' {. QgetCurrentSession().Submit();
3 ]/ _- O# Y1 G2 U: ]9 {getCurrentSession().RollBack();
p* y, ?( \, [6 d...
; l# ]2 S/ W: j6 W* T( g0 vUnbind(HttpContext.Current, SessionFactory)
8 g5 T4 W2 P7 o$ w( T7 J2 l
6 ~5 J" f/ g. x! z1 k2 Q+ h3 T$ ~7 C0 l" V5 hcontext.EndRequest += CloseSession;
! B4 Z3 w) \" j0 q9 _3 U" H3 D8 K/ e7 ]$ A* d' @4 \
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|