埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
1 |; c7 m$ `) ]4 h0 T) X  B  v& Q; u4 W$ R
谢谢- O' a' A0 X) U) [
5 y0 R& v+ u( q2 M' I0 x. Q( A
<property name="current_session_context_class">web</property>- k- z9 O( i8 ^* o. P, n
<property name="current_session_context_class">call</property>9 c) ?1 p* C- u! T1 \
<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 编辑
) r9 n" R# ~4 H! s& S' i' Y+ {  u) R; s4 `4 H& A
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
& w1 N$ A& I, s+ s4 Q9 r* B* |- V2 H
% O& f: }+ J4 z, V& V
  z) o- x5 o" v1 W- EChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
; \! c1 B. `# Q+ i7 G$ x* e. s/ T2 @

; h9 \* _. b: o! @0 EChapter 2.5 Contextual Sessions
: a+ b/ Y: ^$ M4 |( D% c% fgamahu 发表于 2011-7-14 21:56

& a4 L( `" f" [- c
# P& i+ l1 @' V; G! }$ E: K谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.+ H2 M, @* }/ _9 U- _& X: d- e0 p

# M0 M  b" m  k) ?  `现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what9 _& l' j1 ?0 Y1 u; V% W
基本参数:
" @& z1 \; W, {; kjta | thread | managed | custom.Class
' ^; M& Z4 X8 _$ T  ^主要是配合1 q; ^3 _6 s+ R6 \; @0 w6 m) C5 B0 ^
SessionFactory.getCurrentSession()* r6 `8 Z( @+ O/ C8 [
来用的.
# L5 `6 `' j  }% x- f) A* v9 bThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 t8 t- c- C# b/ _Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
3 ?4 f' S( ?4 z1 ccontext.BeginRequest += OpenSession;
4 f4 ]1 V5 i0 s0 T; E7 j! {9 L.Bind(HttpContext.Current, SessionFactory.OpenSession())! S% s2 {6 d' L) P1 s9 {

! t4 g* ^3 z* S5 K( O0 D, o2 I//do transaction- z0 U- i( z4 ~6 Q8 U4 B8 u* ?
getCurrentSession().Submit();
! H0 X$ }# O9 {. g6 R! sgetCurrentSession().RollBack();
% V1 J" f4 U! A( y. t/ D...* R' i+ {$ [/ _
Unbind(HttpContext.Current, SessionFactory)
3 J. v6 V  E% g& i( f0 `1 X
' H) [) `% A! c- ^0 K! h, Lcontext.EndRequest += CloseSession;- a! d  H- \$ {& g$ N2 X; {& L
# w0 E( G$ \% b6 N2 F5 ~
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
大型搬家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-22 23:12 , Processed in 0.128196 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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