埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
7 \6 K0 \4 o$ C6 A6 J. f) Z) z
% ]* _. e8 D' |/ r- Z0 A谢谢
9 ?% y) N, h0 ^, `
  F4 n7 j" o0 w5 ^' X3 J) ]<property name="current_session_context_class">web</property>/ ]9 z2 D  i6 r: b
<property name="current_session_context_class">call</property>0 @0 l, K7 V' p
<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 编辑
8 y# y) [# V; a& H
' Y2 c& [* ^$ [' B6 `3 t; k' `5 n" lPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
( \! }  i2 Q) q) G! [- }$ _0 F/ i5 J' P4 P
# I# T& w2 a! i( L4 @
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' Y8 Y2 G7 E: z" p$ g0 ~

, R' a/ B3 o4 S: w# P+ P- L$ u* d) W& W# g. U
Chapter 2.5 Contextual Sessions
0 i+ |, C/ q! p, b5 v; t0 Kgamahu 发表于 2011-7-14 21:56

5 z( {$ Q" e8 C% y' _  p1 C
) l2 }) V& o7 [  P& ]- P谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
8 ?2 G' f2 ?$ ~1 @7 E) d2 {
, x: F& }) @5 D1 B现在还多了个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
) \0 i' G- A3 r5 A% N基本参数:
) K2 d# V% {/ K! \( @jta | thread | managed | custom.Class. |8 b! J8 d6 Y3 _5 c% V7 z
主要是配合
! s6 l  }$ p0 A1 i& E% e3 j5 q" ESessionFactory.getCurrentSession(). T+ V; Z# V/ i: ^: `+ G6 R
来用的.3 x+ ~+ y0 i* u! Y
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 \2 l& g# h7 |% v" I- `; ~' NWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:, h5 z- |9 k7 G2 f4 R5 B
context.BeginRequest += OpenSession;0 s7 I' n+ l, }  o. p
.Bind(HttpContext.Current, SessionFactory.OpenSession()). ]# L. D7 b/ V* P
' x8 E: m, C* q+ F+ n- t; b* f
//do transaction" M5 S; k# a7 i. s$ f: e  i
getCurrentSession().Submit();" R  O, s; ?5 H; G
getCurrentSession().RollBack();; A% \) n1 \: P
...
6 ?( b9 O& S& N- o( A9 \: y0 hUnbind(HttpContext.Current, SessionFactory). ~" \2 z* e( c6 W

6 K( f( v/ P7 ?$ W* Fcontext.EndRequest += CloseSession;- Q* d9 z( M0 ^( e
6 q, ~; b0 h4 n) V2 a6 L+ ]' A: l
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-9-16 11:43 , Processed in 0.142116 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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