埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
  P+ n+ X1 P. M# |, v; u
0 A: b1 u( c3 J3 i5 Q% s谢谢/ z8 h% O# {5 I. l5 l) \
. Q) m2 S4 L* r' t
<property name="current_session_context_class">web</property>6 f, |8 y6 y# e8 e9 _* z
<property name="current_session_context_class">call</property>, a4 S) W* ^. s' x
<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 编辑
# A, ]" n: B8 A7 x* H5 o$ N4 D+ S3 Z' |
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
4 D% N6 b! ~7 v' `( `- l7 m6 s" S* t  s' U( \, `( `% C
: ]; t/ o" X+ ]8 ?
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
( Z0 N+ l: v0 _" H% `( f  Z/ ^! M  M  r/ I7 x! {- T. u) W! K1 k
# ]9 e/ I, |2 C2 }
Chapter 2.5 Contextual Sessions
7 t* X, a% Q4 t- A# c' S3 cgamahu 发表于 2011-7-14 21:56

9 x2 ], f. ]0 {9 ^; }$ d; m# _  s9 _
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
* k! h" g4 b- f+ B) v2 D! t% _" K( h1 F' 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
& q3 Y$ G4 N0 }% z, o  q基本参数:
  @+ n8 t2 G& c  Y8 y; Ljta | thread | managed | custom.Class
- O7 [- `2 n. F+ t& A8 L  F主要是配合* M+ I  S2 Y8 A
SessionFactory.getCurrentSession()
( p9 j' z8 _9 D2 Q7 g3 R! W来用的.3 b6 Q# b' q( p: f4 u& h, T
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,  c1 w* t7 m% f  i+ h
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
0 t* J5 }& h3 b: c% N+ Q% Z! k  acontext.BeginRequest += OpenSession;6 D4 J9 |6 _3 ?# M( z! z+ E& y
.Bind(HttpContext.Current, SessionFactory.OpenSession())
" a( u0 `! E) h& e
! d1 b$ K# V$ w5 E) R5 E+ V, Z//do transaction
/ T; h' @$ T7 S( t4 r3 h( egetCurrentSession().Submit();6 e  R2 q  {/ o* P* B7 t1 q: r
getCurrentSession().RollBack();
" A% H' ]- U$ s2 _$ z+ M...3 j! \6 }& r6 p
Unbind(HttpContext.Current, SessionFactory)( W+ I% \8 Y# g/ s5 B0 ~( V
4 [" n4 J% B2 Z$ K
context.EndRequest += CloseSession;; \! u( b$ `! e* @$ E( _
1 [% X) ]7 t  ^/ D" I) H% I
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-7-23 22:55 , Processed in 0.124251 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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