 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what5 j; @: K9 n4 @( `6 A
基本参数:% N; |' l: m& A: R3 V: x
jta | thread | managed | custom.Class
! o% s8 `+ ^1 P+ j0 a主要是配合/ H( W8 H1 F/ S+ B8 B; H0 M& n
SessionFactory.getCurrentSession()
7 y( L* Q+ O9 M1 A来用的.
8 ?; l' Q# \, l1 GThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
) |! v. c. z; Y5 Q' CWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:3 `' U5 B( b8 D7 _* H
context.BeginRequest += OpenSession;; n: ^" { @) E0 Z/ p
.Bind(HttpContext.Current, SessionFactory.OpenSession())
* | L+ i8 d5 R3 h" W8 w, R/ ~3 o6 v" R9 ` A* L7 @' g1 F+ N
//do transaction
2 h8 r$ p6 [5 D. y" VgetCurrentSession().Submit();
+ `2 ]& L9 _& d3 R {6 V9 ~getCurrentSession().RollBack();
* ?( o* D( A* i( r' j! \, R...+ h" z3 L6 Q% R- \, A- B* f
Unbind(HttpContext.Current, SessionFactory)
/ _3 V+ O& t9 O2 X, E' T
% {- ~) P' o8 @! D G9 jcontext.EndRequest += CloseSession;/ Y4 J$ E, L8 Y& I3 E* D
5 p( G! `5 w0 [4 C3 h1 ^
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|