埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
' M& p4 L7 ]. t, {% e' J- D0 M) t1 ^: k% f- _0 f. X
谢谢
  T' |" X5 }9 O, ~
0 V! E8 ]% d+ ^  z<property name="current_session_context_class">web</property>! q  S& ~* z4 A+ B" F. w7 w
<property name="current_session_context_class">call</property>
9 J) u1 x+ I9 D<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 L' A# r! d$ R+ g6 x
  j2 _: @* F# v6 Z
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf& |; F6 Y) \. L6 ]
5 m* A1 U4 F7 f, J- J$ X# Y

' G& T' t" \3 `( O( e2 [. T9 ?3 Y: bChapter 2.5 Contextual Sessions
理袁律师事务所
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' r( j4 y0 g- c0 v) U9 A
! A4 W$ V, |+ {0 ?* O. ~, c

$ Y: u; y) s$ b7 f) s% X# g/ J, eChapter 2.5 Contextual Sessions
! I$ a/ }; W! e' zgamahu 发表于 2011-7-14 21:56

* T1 K. z  H3 s, w* u
+ W7 h2 a3 {8 L谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
9 ~9 o% D4 Y" I! H4 q! n2 Z2 z) g: e% A# X0 o& {- R+ r7 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
# r: U9 g8 d  N* [# i* I基本参数:
3 a3 p0 t* R  C& Xjta | thread | managed | custom.Class4 P- G/ B# {9 M7 S
主要是配合7 C3 z& x+ S, X3 @
SessionFactory.getCurrentSession()
) k# P9 a) E0 p% i2 U1 L来用的.
. o! j. f7 L! W- ]# S! G7 TThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,/ p/ h( v5 {3 m. I
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
: f- n- G4 v* h4 o3 Ccontext.BeginRequest += OpenSession;
% U! _9 e: V+ x9 `* o, s' G.Bind(HttpContext.Current, SessionFactory.OpenSession())
6 T1 s0 A( D) m- M, a" C; Z' h. \, X1 b, y
//do transaction
0 Y( B% t6 ^& r' n- |( P! ngetCurrentSession().Submit();( d- t: F& e2 B2 ]7 ~% r
getCurrentSession().RollBack();& z: r) r9 F$ m$ y( K
...
9 X3 `4 R2 Q, z, J  mUnbind(HttpContext.Current, SessionFactory)0 l1 C* t# H. X& i0 X

1 a. O/ f5 ]! B' }. N7 k1 |context.EndRequest += CloseSession;' O2 {5 t0 _4 G3 y6 D
7 H/ Z; u# t1 j* F, q4 {' i9 l
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-6-28 09:40 , Processed in 0.178070 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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