 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
5 F' }( o+ O6 B基本参数:
* Z! S# `7 [+ t6 z4 ]: tjta | thread | managed | custom.Class
7 y& g I0 Z+ m# A. @" l1 h" B- K: `主要是配合, J$ P$ O; f* N
SessionFactory.getCurrentSession()6 A% f& t1 h' v. P1 z7 `
来用的.. z) B3 Y% z! q% e" @
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,( z- t/ |- g: s) Z- b: c9 Q3 D
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:/ X/ B, P$ F1 F; e5 Q
context.BeginRequest += OpenSession;
" Y, ?$ H7 v: P, t.Bind(HttpContext.Current, SessionFactory.OpenSession())6 V8 }4 s+ m7 L- u/ O7 y
! y; h8 K7 L$ r" ?6 b1 n0 }* L. i# w/ B
//do transaction# T, B4 A7 N3 n( r6 G f
getCurrentSession().Submit();
) P- P! _" h, x8 V4 Q; jgetCurrentSession().RollBack();. @4 K# m; l& k: {( U
...
' }, I" V( l8 e( [/ B/ mUnbind(HttpContext.Current, SessionFactory)" x; Q. h8 {9 G
( A- `7 O* |2 Z( A! z) _# ]context.EndRequest += CloseSession;
2 K" { Z3 Q1 q% X4 _9 B4 ^) }* C2 X- R+ j" A
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|