埃德蒙顿华人社区-Edmonton China

 找回密码
 注册
查看: 891|回复: 4

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
& E! }; v" h" d# t" U8 t% a6 [( V2 _5 ?
谢谢  u0 f& d  Z6 m5 M3 s& ]  z8 x

  F3 t  R+ I9 z! |  f. P  c) }<property name="current_session_context_class">web</property>
& j6 ]* q$ B7 P+ Y' F# v<property name="current_session_context_class">call</property>
1 W, L( Q( H' e% v. B0 K" _<property name="current_session_context_class">Thread_static</property>
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 20:52 | 显示全部楼层
自己顶一下,等高手出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-14 20:56 | 显示全部楼层
本帖最后由 gamahu 于 2011-7-14 22:47 编辑
: R9 }3 Z+ C# c; E/ K/ @/ |2 E" f( J! I% W7 K. t. T+ q% F1 \; j
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf1 q9 R( n$ M1 q1 }' M

- [4 [3 _, W+ C1 {0 n$ H2 V5 u8 Q4 j/ s* A0 T% t
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
, F8 c9 b) K2 Q) z. W9 D; m7 }% c4 p; w4 m

# S0 Y, Y2 `5 }7 t$ W4 FChapter 2.5 Contextual Sessions8 E$ V+ r7 a0 r
gamahu 发表于 2011-7-14 21:56

6 S! j  M3 b4 }  [+ L# x, v& T6 [( W3 f" ^6 H0 C
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.- r* x8 k6 Z2 K( O9 p  o( ~2 ?

- o  x$ g- d' d: C0 k8 c: j, t现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what
: W3 K  `9 P5 G! T& ]基本参数:
. k! O( l/ P! E  qjta | thread | managed | custom.Class
6 Q! x  W, {# Z3 }0 f主要是配合
) Y! s5 I/ ]8 H1 u7 m1 USessionFactory.getCurrentSession()
, ?1 l: H' k0 Q4 k6 w来用的.
2 J9 ^) z6 K+ \& {( \: wThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,* g% |, Z; f( w. ~4 j
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
. ^$ e' R& q9 g% Jcontext.BeginRequest += OpenSession;  S0 C* q6 s8 {' \8 Y( N$ D
.Bind(HttpContext.Current, SessionFactory.OpenSession())7 {% q& y' e; `$ x

: X# a- g- z$ R* p  J3 ]//do transaction6 X# ?/ T( i+ W) Y! k
getCurrentSession().Submit();
' H& o0 E) K1 K  e% LgetCurrentSession().RollBack();! z1 B5 |* b: w7 r
...# |  A# R5 ]$ \& Y$ d! |( x
Unbind(HttpContext.Current, SessionFactory)
1 p) E, p8 V6 O) I
+ ]/ s0 F# Q0 {context.EndRequest += CloseSession;
8 i/ i1 v7 @. W0 B7 r
) t+ ^5 }+ o5 D* f" r 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系我们|小黑屋|手机版|Archiver|埃德蒙顿中文网

GMT-7, 2025-12-17 13:49 , Processed in 0.161478 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表