埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?8 o; x# Q* w$ o$ U

9 s6 E+ C( B# C  q! `: F& O5 W谢谢$ p/ o0 b3 w* z( M: n! p4 W

! A" x& \2 M: t+ p, {& C9 }( g<property name="current_session_context_class">web</property>) y, P  Q$ Q  \  c
<property name="current_session_context_class">call</property>* B" q$ X1 N/ J% ?" A3 k8 B, G
<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 编辑   m6 _- C* X8 S

7 v" h( O; k2 L9 f4 G& F( P2 aPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf7 _: `% z+ j: a1 T' Y

9 ^# d5 n' y& D  r* f
+ H- f9 ^0 _% J8 J# T( b0 m6 [' iChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
; ^* e2 p* B+ s' k; L# e
8 H7 v" s/ q2 o/ C6 j: [: l7 r; l
  ?7 t  g. P! ?5 RChapter 2.5 Contextual Sessions0 D$ M4 z3 B) ^1 U
gamahu 发表于 2011-7-14 21:56
$ E8 u# j: j8 T/ O7 O% w
' `: u3 v$ c. U6 Z- H( i
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
  r, |* l$ ^0 j2 U1 G! g4 h. a
3 E9 }' ~8 v2 Z7 G& i现在还多了个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, I9 g7 M+ d0 ?2 a. K& f
基本参数:, h# G1 E/ f$ W, T$ l% U" i0 }
jta | thread | managed | custom.Class
2 W+ S( R; r3 y% B7 F* v) A) M主要是配合. B+ u& W8 s- ^4 d
SessionFactory.getCurrentSession()* L, l+ R. V0 o5 l
来用的.
  m. u/ y  F/ g! \1 gThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ O  {& ]) t7 n3 y
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:: a# V" ^. j  w% h& z% R9 L
context.BeginRequest += OpenSession;( |' }# X( o6 X* z8 H
.Bind(HttpContext.Current, SessionFactory.OpenSession())4 B% c: W( m% L% O8 |: |* }' b

) g: X/ F' U* Z//do transaction1 M7 c/ D: O. s6 A3 N! w0 t0 c
getCurrentSession().Submit();
9 t  i0 m' K# c  X6 M+ sgetCurrentSession().RollBack();  ?% p3 v( B: y& g/ e$ a! S
...
1 Y4 {! b; {& G: lUnbind(HttpContext.Current, SessionFactory)0 ^0 S3 j# W  D/ r( T5 V

+ I3 }7 v6 V; `( a/ C2 m1 n# gcontext.EndRequest += CloseSession;
" U  U6 P9 f" I, D% u9 D$ R  {- r7 O/ c- e
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-2-28 09:56 , Processed in 0.270567 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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