 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
* y; s( L4 C9 F. \' M; R# [6 ^- `基本参数:' y; i: L% E. L/ G( {( H* o# e
jta | thread | managed | custom.Class7 H* Q# N, I- Z3 h
主要是配合
; U" z4 q1 L( F. w% i) @) VSessionFactory.getCurrentSession()5 i5 O. w E8 ?& D" v
来用的. z& Q1 J; z: A3 c* [. V! h
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
$ N, G7 C$ ]- ^- NWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
4 X+ ]7 t# \" y: k+ `; Jcontext.BeginRequest += OpenSession;
" n3 G( G* B& T# D* ?+ F.Bind(HttpContext.Current, SessionFactory.OpenSession())3 V; h$ M4 B+ O
5 X0 I2 j5 z1 ?$ ~- g5 \9 h//do transaction' D' N- o+ s3 Y. W8 |. J7 f( K
getCurrentSession().Submit();
3 ~$ E% m: e$ _& ~. w" sgetCurrentSession().RollBack();
/ B: c5 e* z9 ]0 T...0 H! }( C$ V2 R3 A6 K& |
Unbind(HttpContext.Current, SessionFactory)
* q7 s8 I7 I) ?6 t
9 a+ Z8 e( _6 N% m. w3 pcontext.EndRequest += CloseSession;
* S P# h3 V$ `8 S A2 D0 m
* \( p g4 J% S) V7 P 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|