埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?7 m- R# x" b! V% U
2 A, L7 [- r) I. t- C2 h! ~
谢谢
( W. F/ b) \' q$ n( e( ~3 V3 @. H# ^: E0 T, V- C3 J( l
<property name="current_session_context_class">web</property>
0 ^; r! S) S& w' `$ s8 y7 t<property name="current_session_context_class">call</property>
) M; @$ C/ q5 `9 m* m; V<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. L' t3 n" L& L4 |. Z3 m
% q; g, |6 E! _Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf* z4 y) R$ v4 c( b  T0 k
  |& ~7 S) E! @9 e; c: H
+ M* M, n! M2 H" g9 T
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf- C- F$ ?% L6 W! J: {2 D  U
7 Q! Y  q* w( N6 ?# K( J
5 ~4 t! Y6 f: h8 f( s! I* \
Chapter 2.5 Contextual Sessions8 M" Y# j- ~* B2 u  S, w/ A
gamahu 发表于 2011-7-14 21:56
- h( q+ v4 g. a: j, `, s
0 x' l* |! h4 ~. D2 J3 p
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
* `3 I1 ]( v1 C- ~! j5 g1 G. Q, H+ G& z
现在还多了个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
! s0 P1 s$ c1 N基本参数:
) L' u) S; a. t! \$ G, _7 K. Rjta | thread | managed | custom.Class' t7 o4 w/ B, y" s# G5 H
主要是配合  z9 Q2 G# k+ Z5 ]4 I
SessionFactory.getCurrentSession()9 H7 T/ x' [8 z3 h* f4 q  a$ F
来用的.
  s: R/ z5 \" [/ KThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
: _1 h3 F+ w0 p5 m& Z% S' UWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:* ^3 V+ ]5 a) P. m; G7 S, W7 S2 Y
context.BeginRequest += OpenSession;$ z4 I5 {: t6 I9 S$ s
.Bind(HttpContext.Current, SessionFactory.OpenSession())
8 C0 Q0 V" n; M: O$ B$ m8 z  R: D3 ^. w7 d3 U
//do transaction9 b& x- \: b! o' U1 l3 n+ Z
getCurrentSession().Submit();
; G% W3 u- _2 h/ j% egetCurrentSession().RollBack();2 Y5 \9 `8 ?  k' C: ^% C* R
...
4 Y" F* G4 u- Z! b8 v, i& pUnbind(HttpContext.Current, SessionFactory); ~+ u  j' U( p, T) u! {
& |) [3 P# e5 b0 A8 S. Z! a
context.EndRequest += CloseSession;/ F1 a9 L2 {  {+ I' ?1 t

4 \! i) ^' X! A( K& T1 K4 h 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-16 15:30 , Processed in 0.138389 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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