埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?% Y+ o0 a$ k$ n' {" Y% R! }

& r2 u) E" t( i  t/ s% h! K3 s谢谢
+ f6 S9 g$ d/ b& N8 q
7 N# U- S1 g) z$ W# K5 D6 J<property name="current_session_context_class">web</property>" X; i: h8 ]% ?8 ]& H4 f! x
<property name="current_session_context_class">call</property>
$ G) T" U! J8 b1 q/ G# e/ 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 编辑
$ p+ f6 o; U5 f  @/ [' S; @% h8 Y
6 u9 G( F% t" k8 {2 G- V% WPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf( Q9 @; ?: @, f$ S* x$ h2 O

- i( t) V9 y4 A: Y3 h
: p* W) X% w+ g7 v) uChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
6 w5 l  @6 }. `! ^1 T- x
9 a" X' P5 n  D' B, R9 y2 \% C
! t3 I6 H0 f% V3 @. iChapter 2.5 Contextual Sessions- l( W0 e; k1 t
gamahu 发表于 2011-7-14 21:56
9 ~& ]' O7 h5 h# w: N3 P/ W+ v
  i, C4 B/ _8 Q! q
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
% Q& W( f/ w5 |9 }: W& U1 z+ ~4 h# O" \4 I6 X" o5 @( ?
现在还多了个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; K& J; u  [9 y2 n" G+ m7 C( |
基本参数:
/ ^5 e+ A5 G  A1 Fjta | thread | managed | custom.Class
9 R- M9 E$ {$ @" w) J6 _主要是配合
" r$ a3 K& z( V$ ?4 Q8 kSessionFactory.getCurrentSession()3 _+ ~" Q. }  g, K& C
来用的.
4 z" s/ W' y: D# D+ R0 e1 g2 |Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,! ~( f1 Z2 X. `/ T6 R7 J
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:* L5 {+ w* a+ e" W1 ]
context.BeginRequest += OpenSession;
; g6 h2 R' }# j$ A$ b.Bind(HttpContext.Current, SessionFactory.OpenSession())
  @8 u9 X( f3 @! p4 K, i
. P( R. a7 A7 R0 i$ h//do transaction
# j9 q, _! R1 |% q- Y0 ]$ f" [getCurrentSession().Submit();
5 \- J2 A# ~; agetCurrentSession().RollBack();
7 v3 N$ O' V. t/ ^' g. p2 c...( H9 \! W/ `4 f0 r, ~! B
Unbind(HttpContext.Current, SessionFactory)- d/ N7 c; q. m) }
/ @( x' `1 i. \! f' ?4 f
context.EndRequest += CloseSession;
- \- f5 K  t) U. U2 o) y
0 `; m7 o: N+ r! z4 u 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-16 08:57 , Processed in 0.112535 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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