 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
; {! p) X* U8 R; ~) `基本参数:$ `# i/ l- {5 t. I6 \# E( t! b! c+ r
jta | thread | managed | custom.Class# V& Q5 G5 v: n- F8 h
主要是配合9 O7 F& p* R& O' i
SessionFactory.getCurrentSession()
_# q8 C% d- { H, l4 U9 A来用的.
. k8 i+ v8 N4 z9 kThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
* Q' C' ^9 _1 c/ K$ Q+ W F1 F+ H) OWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
0 j! I$ x% d( C5 D8 l! t7 ~context.BeginRequest += OpenSession;
* e2 n1 e R1 e" ]$ n/ }.Bind(HttpContext.Current, SessionFactory.OpenSession()), s+ E8 u8 i( g1 g" ]" s- x
3 ?# N _0 ^+ G6 y6 d
//do transaction
& { P$ a" }3 v$ G9 B- GgetCurrentSession().Submit();+ u5 h7 `2 M1 Z. D7 \1 T
getCurrentSession().RollBack();
! i& G! Z% `2 Y+ R, a# u! B.../ |& E! x) H! a6 \
Unbind(HttpContext.Current, SessionFactory)
$ n. i j7 c% h$ _ q8 F+ b# B6 t3 \2 {
context.EndRequest += CloseSession;$ t. c; j1 {6 H# x
3 [+ T- _, M6 c/ f/ z" d 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|