埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
) A  u, F5 j5 b1 u7 O% X! }# D- |2 Q
谢谢( {, R& [* A& U

  ?: B3 w) l6 P8 u& ?/ j<property name="current_session_context_class">web</property>
5 h6 @. M% `5 K0 N1 N<property name="current_session_context_class">call</property>
" D1 O7 C" ~  Q* h: C0 F1 ~- b3 B/ Y<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 编辑 ( R! \8 u0 j6 s3 h- i" P3 Z
0 w! g7 @3 B5 C, C9 t: H- I
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf# d/ |1 X1 {# K
3 M' I, H; `4 E0 ]6 G/ q

# U! L8 a) J) T  @' X4 `( YChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf3 r! ~6 ]: P. k" s

$ E1 R0 w- Y" z8 v: J( B- E- n
( s- O. a: _  W$ d, }$ s7 @Chapter 2.5 Contextual Sessions
. l% E1 D! ~+ Y3 Ugamahu 发表于 2011-7-14 21:56

+ X: Q/ B: t' M1 t/ Y$ I, x# s. k. N# d6 m
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.% y; X' J  V* [2 R' g
3 f: ?% Q8 I3 \$ p8 D
现在还多了个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
' U/ C, g  O# P0 z基本参数:
! ?# I( I7 ?& `$ w/ njta | thread | managed | custom.Class: S$ F9 g6 h3 E
主要是配合
. g6 H$ p& C$ V; G) L9 V% TSessionFactory.getCurrentSession()7 v4 \8 Z4 Z+ U( W7 f
来用的.
2 e; g2 X9 X0 @( r8 A9 a) a: }, hThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,9 Q0 w6 [5 l$ V& i$ ^
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:( G! G' L/ ]) B- b' ~
context.BeginRequest += OpenSession;
+ [0 a) B2 S# Q7 E+ T.Bind(HttpContext.Current, SessionFactory.OpenSession())0 o0 `- l6 z9 Q" f0 ^9 a9 G6 `

3 B& ]4 s. \: W. Q; z//do transaction. M7 }$ Z# h: v% q& v1 l3 N+ ?
getCurrentSession().Submit();
; c# _1 F6 r6 S2 B  ~getCurrentSession().RollBack();, t' Z9 ]" D1 g2 f- s
...+ |# H7 e5 M% y* N( A
Unbind(HttpContext.Current, SessionFactory)- h" g# k% `) e1 o

) G& d; j  d7 ^# @! [; Zcontext.EndRequest += CloseSession;. [6 g: v' E0 I+ Y, K! W% \" K, R

2 h) T" }" u- G- u8 l; t( \" ?( M 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-4-28 04:30 , Processed in 0.162213 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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