 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
3 q9 S$ T' l% H. h$ ^+ U6 G$ {基本参数:. d0 |5 U+ M6 m% m- `
jta | thread | managed | custom.Class Y; J- s D& x1 @+ g5 a
主要是配合$ R9 [1 q2 L8 m4 |$ a: \
SessionFactory.getCurrentSession()
3 j& p: A# H% [7 K: T来用的. Y* \- h$ ]: ^
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," I5 ~# Y9 d7 I U+ N- y) [
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:. Y2 n4 |1 u5 l
context.BeginRequest += OpenSession;7 s8 W" G5 f0 O4 T2 V) g
.Bind(HttpContext.Current, SessionFactory.OpenSession())
) Z+ u& e& A3 l7 ~8 h4 U* V/ r# ^$ s" X" g0 ~
//do transaction
- M! ?& m+ ^9 K+ }getCurrentSession().Submit();
" e8 T) _8 n3 F7 H1 o9 S3 q" P' EgetCurrentSession().RollBack(); d ?. S8 N) x. n: h5 j% W( ^
...
7 p8 L( {5 _$ m% `( B9 F oUnbind(HttpContext.Current, SessionFactory)/ Q. P* |. Z: ^6 V k+ k4 m6 w0 }
, X) L) s8 ?( g. g$ N; X& vcontext.EndRequest += CloseSession;
, A2 N: @- f( J* r B5 E
9 G. d# F0 o! r+ r! a 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|