 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
5 t; f% d9 t3 a# V: ~6 x$ v- C基本参数:6 d4 U7 L8 g, o/ \7 u$ W- ]
jta | thread | managed | custom.Class1 V8 F0 n: p3 [6 z
主要是配合7 s6 z Z5 f0 N2 I( u, ?
SessionFactory.getCurrentSession()9 e2 |" O* N# f, s# m9 g, T
来用的.
- G& e& _* @* x! H. ?* dThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确, E7 |' Y1 }0 N2 N$ {) R. S5 T' m
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 U; @* t6 s7 u( k! J4 b" kcontext.BeginRequest += OpenSession;' @: s+ D1 l3 Y$ q+ b9 I9 e9 m
.Bind(HttpContext.Current, SessionFactory.OpenSession())
* ]; S3 k- ?1 P+ x% t% Z7 g& c2 I5 Z* D( Y& @9 J v. D
//do transaction* H& P, O* N. T$ J& w- c
getCurrentSession().Submit();
. C3 E: F- ]; `3 X' egetCurrentSession().RollBack();
; o1 E# ]( {+ ?* m4 o" h...
4 p H5 P9 g) b+ N! M! |% v. |Unbind(HttpContext.Current, SessionFactory)
; n, E' I3 `, C: u" \
9 l" R; [" e. W- y5 |7 Z1 N9 Icontext.EndRequest += CloseSession;# z) G* P' B' R$ a
* A6 k2 k- u* L- P+ T9 X 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|