埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?  E" r' \7 O4 O& n& E* H( B
& T) V" x! X9 u$ P5 o
谢谢
4 w* J* n3 E# i& @$ m5 N% ?) G! X# X1 }; _
<property name="current_session_context_class">web</property>
. V$ M# h" F/ w6 M8 a' H' r7 V<property name="current_session_context_class">call</property>1 R- }3 R- J7 M4 u+ E+ c, E
<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 编辑 / x2 x5 ^. q  n8 W5 F3 G4 B3 ]

' j8 U& n( {/ R; k$ \; LPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
/ r7 \6 T& r0 o$ o* Q) h  e3 @" J# z% Z9 n# r3 U. U: n7 [

4 [  ?0 a- b+ oChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
& L6 }3 ]; G+ K3 l. V
/ r" [. x* X9 d. k; {
, e! x$ j: K$ E$ i/ `Chapter 2.5 Contextual Sessions
& q* S3 F; X* D$ A: v& {( Lgamahu 发表于 2011-7-14 21:56

0 H  D+ k# G5 I) Q. m. h1 K' e4 a- V8 ?+ W1 q* q
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.+ j* Z& s. u- U9 X  I
; t! Z0 G! q& O) |
现在还多了个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
! T$ A3 f! m1 b9 A8 P% L0 R- [基本参数:
+ J! l. z8 T& q5 V$ \jta | thread | managed | custom.Class- Z4 y+ P/ R! T9 f: e: H
主要是配合
( G. s  Q1 _4 q% I* _1 B2 oSessionFactory.getCurrentSession()
6 I) f8 P4 a7 n4 T1 U) D来用的.
2 {3 s5 v% o( L+ pThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
; }6 x$ m' r: T, MWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
; {8 u+ K1 b6 f3 L# x5 Zcontext.BeginRequest += OpenSession;1 o; ~- `0 W# n' U& r
.Bind(HttpContext.Current, SessionFactory.OpenSession())( p: q( M) J) Z7 O+ f8 ~2 R  l
* J% U' }7 q" c/ H5 Q
//do transaction$ Y$ @& q# Z% o1 y1 R4 y* o! h
getCurrentSession().Submit();( K. x, x6 h/ f8 |) V) l0 ~
getCurrentSession().RollBack();
+ @- s# X- {4 j  u...: U- E: s1 g: {
Unbind(HttpContext.Current, SessionFactory)
; w) q) z7 ^6 Z1 y* E* g% K1 [) Y) C" a. A
context.EndRequest += CloseSession;& P) }1 f: r- E$ L) }$ `, s; E
; W* s  @9 o8 x+ c, m: `
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-21 10:04 , Processed in 0.106571 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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