埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
$ T8 g9 D, }. u) w8 l* p  o7 \5 }
0 t" V9 {2 o: h: }' {: C谢谢
# G1 \8 S0 Y! {/ \/ m6 z2 r' o% _3 m1 g; r
<property name="current_session_context_class">web</property>
& F& a) o, K0 X1 n7 S& s  T<property name="current_session_context_class">call</property>
2 t3 S; C& |3 u<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 编辑 % m: k. f' |# C7 Z1 v/ \( c

) P+ a6 z% b+ J7 T& L% }Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf. G+ ^) V  A0 d( h* S" l% U/ a
& q8 b% ~- h6 y$ q. c

& ?8 `1 D$ J& h$ I2 \Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf6 V* ?4 f2 @: X/ b* o" ^6 \# ?& j6 p/ f

  C8 e0 G" }" ?; p% `* _: v$ C6 W
/ E7 }2 Y& p9 _& `, q5 t  wChapter 2.5 Contextual Sessions4 d; _  b; g) j+ ~: P
gamahu 发表于 2011-7-14 21:56

! g' t, U* P0 F9 z* y- v6 q& k: }0 N, N. ~
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
6 h4 |+ }" V. R0 E
& k' X) e  c) K6 U+ M" i- i现在还多了个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. L7 z8 d, W5 i( l8 b
基本参数:$ l$ ~, K* g8 g: k0 l& H+ {
jta | thread | managed | custom.Class
) g; g: P+ I4 D% E% o8 X  @/ {. m0 \主要是配合
$ K: W% r0 Q! H0 `1 A1 @0 DSessionFactory.getCurrentSession()
0 r3 b% }# d, r, s: U1 u; H3 K来用的.0 `5 s$ ^+ E* f. d7 B! B" t, h# G* x
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,9 ~$ Z3 |/ p0 R# z9 N
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
, {* A2 v9 F( G1 P' h5 Gcontext.BeginRequest += OpenSession;5 B. N5 Z# b  p* {
.Bind(HttpContext.Current, SessionFactory.OpenSession())5 g0 _) E( n2 k! q) u

. G; S9 o% `3 J* _//do transaction# f. F6 |: k: ]+ U
getCurrentSession().Submit();
3 o* p) E2 I# Z$ }' r, ~getCurrentSession().RollBack();
" V! d) N; Y( P1 l5 S...
! \( m) g* N) [4 Z6 x* ~Unbind(HttpContext.Current, SessionFactory)0 r) k+ B3 B7 ]& Q- Y; E2 m
% L- `9 n  E% d; }' z
context.EndRequest += CloseSession;
: t4 f1 }9 r# b! T, \
% @; r6 ?& |6 |4 ^( c6 Q* a 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
理袁律师事务所
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-7-5 12:45 , Processed in 0.131814 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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