埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?! V4 ~2 U1 d+ d  h9 ^# X# l6 ?

- b! Q+ L7 y0 T, a( u" o) @" N* X谢谢7 [  H9 d# u0 U; }5 K) n

) ~, L' M5 m0 J1 _<property name="current_session_context_class">web</property>( y) ]* @* w( d, a& g5 @5 m$ c
<property name="current_session_context_class">call</property>% b9 w6 y# m8 |, G: ^! c
<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 编辑 9 x; U! _5 O2 @1 D* a! R4 B

% g5 G6 i3 @! y' j0 F: FPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf/ Q9 M5 [# q' q: I8 |$ y* G6 A
6 w( x5 l3 K2 z- T/ j

& Y0 |9 ?+ T8 `+ @Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
; k$ l6 P+ G5 t( h& W
3 T$ F1 M! L; f) ?3 \
2 F9 y! h/ |+ l& o6 S' SChapter 2.5 Contextual Sessions
4 T  Y2 R4 b$ @4 ^% q& |gamahu 发表于 2011-7-14 21:56
2 P$ ~  H  R, f$ a; Y  ^. y

$ _8 B* S4 M. C9 w) g* J* B6 U$ q谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
7 `  Q3 g2 m# z3 B2 E9 j& L
, q$ F+ E$ X2 z3 B- l2 S: H现在还多了个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
0 @( n+ f( X! |* r) U" G$ u基本参数:
+ u* f) t9 T$ G0 ?2 F9 e/ d% tjta | thread | managed | custom.Class. W6 f8 G* _; Z# H- T
主要是配合/ b2 @# N# i. V
SessionFactory.getCurrentSession()
+ {" e7 J$ C$ j6 N" p/ N来用的.7 z' y( `+ ~* g0 I+ \
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
9 B6 t9 e8 Y9 n8 M: uWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:2 W8 w$ Z' O0 S- q: T
context.BeginRequest += OpenSession;* U; h  `# `3 C! Z
.Bind(HttpContext.Current, SessionFactory.OpenSession())3 q. `9 p2 \. M* ^7 C8 l) K
- }0 h9 S7 P$ \$ i& L
//do transaction' |7 b% I) m1 r' P8 Q  `' U
getCurrentSession().Submit();5 \' E) r. c; u( v4 O
getCurrentSession().RollBack();
0 f7 m7 q- K( _5 K! S...& E: s$ m0 s1 o8 n
Unbind(HttpContext.Current, SessionFactory)
9 z3 ?) k4 }6 Q& n/ i* ?' s
1 r" f# s& x4 ?( k6 Lcontext.EndRequest += CloseSession;: a7 P% V! Z' S7 Q, f- Z& i

! \, |7 P, H( `- O 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-8-23 08:23 , Processed in 0.163992 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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