埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
( R' H1 i- `$ G4 C# P+ _3 R+ g- \( o  P
谢谢6 @- p& f& @0 N/ }/ u8 l
$ f- E) `3 m  }
<property name="current_session_context_class">web</property>9 R  r) ^, u2 J6 x9 j2 a# G& M
<property name="current_session_context_class">call</property>2 p: ]$ K  U" _5 B
<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 编辑
8 z/ L1 j2 O9 H( G. s
) |& ^! w" W( o/ y0 x3 u8 @* {: k5 FPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
4 H1 ]4 a2 D9 H
3 @8 U) \. u5 m3 ^1 z/ m  _- c! v: Z: d
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf" d" R. J- k: ^+ t! D4 ~
; g$ t+ j( ?$ N1 p

/ K$ z: T5 W3 N6 w; qChapter 2.5 Contextual Sessions
8 m. C! t8 P# f" k/ _5 t0 G- R3 h+ vgamahu 发表于 2011-7-14 21:56

5 ?6 `; R$ h/ m9 H/ g+ }. E% B7 ^% L" k6 w/ o/ x/ j
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.3 m; n: m. `% c9 I. u
9 r  ]. m, Q+ R' f9 L
现在还多了个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
! @$ e, _4 N" l# o7 h: R# j3 W基本参数:, s2 i$ Z+ ~1 b
jta | thread | managed | custom.Class
* s, u- t" {* A主要是配合, |* D! `6 ]+ ~6 M, O* t7 h" l
SessionFactory.getCurrentSession()4 [1 U: ?% C" d4 n% u3 ~/ N# T
来用的.: E' d0 }% g; w$ x1 i9 U
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
+ A5 c' y- C1 TWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:* ]  h- _* B: G; f, @
context.BeginRequest += OpenSession;( `7 Y7 F% q7 j$ K
.Bind(HttpContext.Current, SessionFactory.OpenSession())
* O. l$ ~. V  k" W6 z) ?
  `. v6 I4 ?3 r6 l- t! E0 q% Z  r//do transaction
5 n; w! T9 ?4 c0 `7 P. MgetCurrentSession().Submit();( b( i. u8 L; [6 Q! f  \
getCurrentSession().RollBack();$ A' H3 d. w" P& G/ L) I/ ^
...
: i3 ^# j0 H/ h- P5 [: a5 W+ PUnbind(HttpContext.Current, SessionFactory)
4 \: _" r' L  j( m
0 W7 I% E! U3 v8 e8 |context.EndRequest += CloseSession;, Z+ N# U: L0 G  t! U6 U( D" P: P
: h( g1 t% }# ~8 R9 s( h0 k  @
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-30 19:06 , Processed in 0.076964 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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