埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?) R* h( |) B  \- A3 _& D

1 }; H! E1 O3 C3 Z3 E4 Y0 |$ E谢谢
; i2 L' f/ g6 Y4 F+ D6 ]+ C& E" h9 V6 P# T9 |, Z
<property name="current_session_context_class">web</property>" t/ L$ L6 [( ~9 B3 }
<property name="current_session_context_class">call</property># B  ]- N$ x. [! x) j
<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 编辑 * j2 r% N) b* R  I& A

. v0 I$ n  T7 a' c$ v8 TPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
' g& }- X" A- V, v! ?( q
4 M! y" \: e' X6 h! F& \4 {! K6 [. n- ]5 w1 x+ O3 O' t
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
. F  P8 X' f0 Q; ?5 Y- Z3 r5 l! k4 |- [4 I. q( }, e' f

6 A" R: I6 |0 m6 z% n& WChapter 2.5 Contextual Sessions1 A' }5 i: r$ z
gamahu 发表于 2011-7-14 21:56
; G, f3 T- x, a- C# ^! L

& Z) _: d# t( \, q, y谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
* ?  c/ u+ L( ?$ l6 }5 ]7 \2 Q7 e" y  w0 r
现在还多了个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( {& {# S4 c. |5 X! U0 ?( L
基本参数:
( X* R& }$ C, l8 Rjta | thread | managed | custom.Class8 `6 K/ X- d/ ]) h7 f. X8 ^
主要是配合6 y% ^, e; |2 ~% s3 ~2 _  _
SessionFactory.getCurrentSession()
, l# O, k( f" p来用的.
  s3 K) w9 ^# w9 G* K; _( A5 WThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,; V8 v7 s4 I/ m% P! E# Y: f
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
0 H1 u- j7 _0 F; n2 f5 _1 Ocontext.BeginRequest += OpenSession;
; N3 f& R- K3 o2 G8 A1 w.Bind(HttpContext.Current, SessionFactory.OpenSession())
  H* J' H% L( G# k3 V6 |& F2 @& [- O2 k1 S2 v* |1 e
//do transaction2 `+ q* b. x* ?& l
getCurrentSession().Submit();
& e! G& y# s$ ~( z8 [3 Z9 Y8 igetCurrentSession().RollBack();" w! b" s+ }. ^# R/ z" T
...
3 r2 E  `" W9 G9 \' EUnbind(HttpContext.Current, SessionFactory)  @- E% Q5 Z* l7 l0 Q

8 Y" n. v; ^" [# m9 j8 {context.EndRequest += CloseSession;4 s2 {- R7 h% X
) I/ _- Z& ^/ x
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-11 14:00 , Processed in 0.104842 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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