 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what3 f- H: I5 e8 f- `
基本参数:, |& q8 c9 A8 c1 F( _4 i( W$ g
jta | thread | managed | custom.Class
) o- O8 Y/ o6 H主要是配合& M4 S9 W Y k5 p* ~
SessionFactory.getCurrentSession()
9 M% r( }: }# B6 N7 U% ^9 {来用的.
- s8 U! e/ W# C( f2 m1 ~& J$ UThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 U# f. ? c% M* m0 w2 `& G9 KWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:. N: M1 g6 k3 y$ O/ g
context.BeginRequest += OpenSession;
# R- V$ g! ^- g. b7 n.Bind(HttpContext.Current, SessionFactory.OpenSession())
~( B1 v* a, J- F! J& o
, U" p" i$ H2 [! ] f/ p2 a* `//do transaction' f: E5 Z; t, a; E Z" g# [
getCurrentSession().Submit();
8 o( a* W* m3 K, ~2 zgetCurrentSession().RollBack();
% I/ T; T" q, o1 @' J h1 ?) I...0 X) x: t9 J$ i: t* X! p% k4 m# X
Unbind(HttpContext.Current, SessionFactory)
9 y2 N6 P4 E1 w
& t; |8 h# v+ H$ A) K* [context.EndRequest += CloseSession;+ z' [1 |: a) s3 @* r, S+ I
7 P1 L9 p( Y | 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|