 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what- `9 S D1 C5 i0 }/ J
基本参数:7 u$ l. H% J+ | M
jta | thread | managed | custom.Class
* m5 g7 g& c+ S i7 Y J7 `3 e' H主要是配合
. o p) p1 ?7 W6 T) R" E" HSessionFactory.getCurrentSession()
9 Y% A8 J/ ^0 s& |$ e1 V( `. W来用的.! O) \4 v. i0 b/ n
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,' f# m+ C6 l" O4 B% i
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 y+ k! b6 a1 d+ w" ^/ n
context.BeginRequest += OpenSession;3 R" L! R( e/ [2 ~
.Bind(HttpContext.Current, SessionFactory.OpenSession())6 L' l8 \; q- `9 v H4 \
* [' y$ g# d7 g5 S//do transaction" d. u0 p5 B2 W% s' s1 K
getCurrentSession().Submit();
- Y3 C8 ]* h5 h& R1 fgetCurrentSession().RollBack();# s% X2 L" `' s; n/ G2 {8 Q, R
...! H. E' [6 X+ n
Unbind(HttpContext.Current, SessionFactory). q& g2 a5 ^" U, {
( \5 }: Z0 D" Zcontext.EndRequest += CloseSession;9 _( O5 D1 j5 w; d6 V D
- R! z& Z4 O9 A1 B3 y I6 y* V
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|