 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what5 ?2 y5 c) k6 m1 v, g" _
基本参数:
8 C% K& ^9 G0 z% n, b8 |jta | thread | managed | custom.Class
: f# o+ V! Z! l6 H8 b主要是配合
9 R1 D5 q# L) l9 o; l5 n8 F" DSessionFactory.getCurrentSession()3 k5 f! k2 P, [
来用的.
* U6 K2 M0 a0 O8 QThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,- h. \& d2 S8 |5 b. L5 t3 c5 Q
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 v- q6 ~. j' J& p- O& W% q" ^context.BeginRequest += OpenSession;3 d( W" x9 H' s
.Bind(HttpContext.Current, SessionFactory.OpenSession()): d. b, ^. Q: h
. o4 H, [7 G/ |, g" ^
//do transaction
7 K$ g& f& \, b( V$ ?* Q& EgetCurrentSession().Submit();
+ g9 \+ L, R3 ~0 {+ n2 igetCurrentSession().RollBack();& G$ ~& Q* d4 l4 v1 n
...6 a) z- A0 Q e7 L0 u* O
Unbind(HttpContext.Current, SessionFactory)
' r2 T7 x e2 f8 l; ^1 R3 ^2 b# {4 j+ O# F, E: L1 T4 p' [$ s9 S
context.EndRequest += CloseSession;
- Q. e4 j& b- R) j
+ ^8 {% u$ w @" @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|