埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?; n+ x3 S; f( m$ t; o9 A/ u8 e4 y

" m# e/ q: H/ a3 A' f0 k" r8 m2 A谢谢/ R( @! b1 q3 h. z4 Y/ D* ~

  {3 {. H$ v8 g( Q<property name="current_session_context_class">web</property>
  t! B% r6 ?5 D; ^+ B<property name="current_session_context_class">call</property>
2 D4 N/ |( q+ w- _! I+ ?<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 编辑
7 o6 D9 e9 A/ p& M/ X1 b1 ~
; ^! Y) `" q; l4 E' \  t- b" ]0 uPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
, U$ e/ v' O) ]; ?( R9 D. h5 z4 c4 t

4 u& {9 N) N! z6 V3 \8 J, g* |+ m3 xChapter 2.5 Contextual Sessions
理袁律师事务所
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
6 S4 g% b  U8 h0 ^1 F9 F
0 J4 T& V% v% ~! ^, I) {' V" o+ n4 X8 R) K  g& n9 t8 a
Chapter 2.5 Contextual Sessions8 j8 N" E7 F$ l" b4 {  F* _; {% l
gamahu 发表于 2011-7-14 21:56

( w% b' c) F# e
( |7 N1 {# |! v, E2 ~  p) S谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.* I* p' N, {' E9 G3 ^" f" T

2 r" C2 V) H! ]6 E现在还多了个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) \, L$ ^: e& c
基本参数:
$ |, p) ?& c/ ?7 @% ^jta | thread | managed | custom.Class& y3 a6 J/ H) a3 i& d- t; X' ~" k
主要是配合* w2 l: Y; U7 ?9 x  _
SessionFactory.getCurrentSession()
0 X; e' p; w# _- n/ s$ N来用的.0 P) w% \8 W; {- ?; R& g7 a
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,  o2 p8 U) c2 T8 D. P
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:9 N  D2 K0 I7 K6 Y
context.BeginRequest += OpenSession;$ X% y( E9 w$ v- ]1 E: _
.Bind(HttpContext.Current, SessionFactory.OpenSession())
/ i- z9 `$ c. L3 p; F+ T6 M1 g  |. H" c
//do transaction
2 Y; Y3 x6 |$ W! B. Z( zgetCurrentSession().Submit();
+ L" k  p8 c' ~7 h9 i; F5 \  ^0 igetCurrentSession().RollBack();- W' B$ u! z* \
...
! s) K5 Y& {3 ]" b2 t* JUnbind(HttpContext.Current, SessionFactory)
, s0 x3 g! y; r5 S4 E- E! n' h' L; B% J
context.EndRequest += CloseSession;& O- A. Q7 _8 t: e3 w
6 s  i0 ?' {; `& W% l1 Z7 s
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-6-11 13:04 , Processed in 0.124258 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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