 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
6 k; q% f- O3 f& |基本参数:3 O6 T) o" n5 L; z# ` u
jta | thread | managed | custom.Class
$ h3 l+ T. X- B% N. e" u. `4 p; @" S主要是配合# o' }, g7 g* A9 N* B
SessionFactory.getCurrentSession()
1 _7 Z5 q# @* e* e: k$ H; D来用的.
3 d0 g" W$ D6 m7 B* q5 AThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
, R7 \" F: B5 A, I: _; vWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
4 h" c8 ]% _6 y( n5 mcontext.BeginRequest += OpenSession;
* ~5 C( n3 s. ~ @: x1 i.Bind(HttpContext.Current, SessionFactory.OpenSession())
+ E' |, ^% `( \0 M
# K0 c5 ]$ f# e! n* o& n//do transaction
: j; z4 H! n4 Y* W9 P: a0 ]getCurrentSession().Submit();& v( r0 r; W' x. I
getCurrentSession().RollBack();
+ b$ K" p. J0 m7 ~...
4 |: P [7 h+ L1 c: i3 m5 dUnbind(HttpContext.Current, SessionFactory)% w# d9 G% M O5 W( \5 |
' V& ]% Y. U4 z) Zcontext.EndRequest += CloseSession;
8 ]8 j% @( C6 `# \/ e
6 d9 a" n/ z/ E5 T$ l& K 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|