埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
: o: J' d1 a& c# v! C6 J  z( D1 \, R" Y
谢谢
. l% f3 A0 I; Q/ E/ R) d* x5 c0 b) R0 `% E+ _. c6 T; ]8 N# V
<property name="current_session_context_class">web</property>2 |) f9 w4 L/ J2 V4 c" |" k
<property name="current_session_context_class">call</property>
" X( l6 |- Y( F- @' s<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 编辑 4 R# D+ F0 ?% D" B: Z0 h9 h
3 w% E! u$ b: K7 U' i/ N
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' z8 o' X, n+ `$ X! O

+ `: k1 k# P6 O. B) y( h
6 d, l, c3 R4 ]Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf# {7 ]/ i3 l& Y2 J- r0 U! y6 |; V

% M% ~* |( n3 L  _
5 `; c3 z0 ?% J5 `Chapter 2.5 Contextual Sessions7 Q. _/ M1 F0 K5 x0 a
gamahu 发表于 2011-7-14 21:56

3 O, f% j- F8 z" s4 ?' k5 c- \
2 K! R8 J. U0 M" u1 }( \# Y2 B谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.2 H0 U" {# K, C1 X8 ?

) O1 I& M6 o( o% R8 i现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
理袁律师事务所
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what7 {- s, O3 C" F- c4 H8 Q+ r, L
基本参数:6 z. u$ d$ S3 q! g- [% Z8 E
jta | thread | managed | custom.Class
: g# m1 E; ~$ H8 |, A主要是配合
9 y1 @6 P) P# f) ^" ~" u5 M- _SessionFactory.getCurrentSession()
6 @2 f* Z) a3 _" m9 _3 I来用的.- ~! z- Z9 u! x- P) s- |
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,) B4 s7 }$ Q& J2 W% E4 ?: u
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
1 b  T" ^/ ^) ^/ b( _3 ]9 {+ M+ C: Scontext.BeginRequest += OpenSession;) @6 G" S8 s0 l/ M% Z# ~
.Bind(HttpContext.Current, SessionFactory.OpenSession())
! r, |  E- \5 V  D3 N# q( Y+ [4 q" ~4 ]" e$ }( R. b
//do transaction
8 B& o# l3 u7 i7 m! l& AgetCurrentSession().Submit();  [6 O9 z1 H* q& \! O6 k
getCurrentSession().RollBack();
& K+ c9 }$ ]6 B/ p" F6 o7 T- E7 o...
$ |; V% J2 G" |, gUnbind(HttpContext.Current, SessionFactory)
6 s. q0 |/ W( w4 y- L0 `$ v
! |4 O$ y+ F7 D, jcontext.EndRequest += CloseSession;/ f1 ]7 k4 R) ?$ _0 h) ]

9 T$ a* ?7 ~+ O7 X 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-8-11 22:47 , Processed in 0.146644 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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