埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
( A/ V! J% y+ H: j, ?
3 \! c4 m& g! H" h. ?谢谢
5 Q. H& P: `8 X; ?2 p; ]) R' O4 p7 f1 I3 D
<property name="current_session_context_class">web</property>
# K0 G7 u$ |  a0 J1 I4 d<property name="current_session_context_class">call</property>
. t* S% b, w" l6 B: @, Y<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 编辑
- V7 P8 x" A; L# V# H. F& Z' g- U& L6 \
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf5 p/ a3 M8 T' {5 u# X

; R+ J4 q$ }( L2 [4 }6 t: T; P. ~) L7 Q6 ^3 R( ^5 F
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
  A9 e. N0 ~. l8 _; R$ C
0 V* f4 S* s( [9 z0 K/ d
) {0 Y: b6 _0 N; T, m8 n9 \Chapter 2.5 Contextual Sessions3 s- O" h3 D- J' ~3 x
gamahu 发表于 2011-7-14 21:56
' Y$ u. l: Z9 h

+ f" V0 f7 n+ f$ J谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
' e) a/ p3 [+ {( n* E- E* U: e, D  j" t( Q+ q
现在还多了个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# X) F4 B$ |- X2 O9 R
基本参数:' h9 v9 \! s$ E3 h4 o+ k# C
jta | thread | managed | custom.Class, p. ~, [. \3 q* _) z
主要是配合
+ C! f8 L* ^/ d; c' h6 a1 XSessionFactory.getCurrentSession()
: p  Z/ S( I! U& `3 y" V/ j0 b/ G  [  `来用的.4 _+ ~$ m* k- _% J% f5 e
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,8 U  q% [2 y+ C7 O" o: Y
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:$ G( V6 w/ M, D9 H, a  W( e- Q
context.BeginRequest += OpenSession;& d& p6 [4 i8 {" L4 J
.Bind(HttpContext.Current, SessionFactory.OpenSession())# G) K" s5 ]- s" m$ M2 W2 n

, w2 B& \. n2 o5 }//do transaction3 E) E- t1 Y7 o; n
getCurrentSession().Submit();; t, o3 m8 C8 ]# M- x0 G9 k
getCurrentSession().RollBack();
( `; R& p% X, g, N1 b# J6 T8 y...
% j  y. T1 X8 V# z9 g- |+ mUnbind(HttpContext.Current, SessionFactory)
! X" |: M" t% w0 H3 l1 @3 j+ P$ e! j; V4 B9 E
context.EndRequest += CloseSession;- l* k9 N4 {  g/ \
( \) y2 B3 D% K4 L3 d$ d
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-22 09:14 , Processed in 0.142683 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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