埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

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

% T7 y9 |. T0 N/ |谢谢
, U1 Y; ]% q+ k7 f  G5 {
" h% ]3 P6 M4 T% w6 t<property name="current_session_context_class">web</property>0 k) I, L3 c# Z- O# d
<property name="current_session_context_class">call</property># @# y: q* Z$ w% b9 i. `) q# W
<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 编辑 # \( H8 ~# `. K1 H1 ?1 C
/ n5 a4 [* u$ K' E+ S' I
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf6 k5 g0 s2 }& g0 |8 F* u
) ]5 S8 U1 H8 u4 k; z

+ e; s0 q2 }$ t0 X+ l2 L/ ?Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
9 b6 D) P3 t! ~6 K; {2 g  x* ]
9 {6 A" G6 p5 W% |4 e0 o; x! v: `* W7 J
Chapter 2.5 Contextual Sessions4 f4 ?0 D" M* e
gamahu 发表于 2011-7-14 21:56

3 G! A) `3 N# k6 T0 d. o6 ~  I# a6 J" z0 j. S) |- V5 y, j- k
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
  u  P- E* A# s- @' D7 u# ^. z9 y# ~: ~4 N! x
现在还多了个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
2 \6 j4 P* Y- u! D! u基本参数:6 R. ^" {" Y# Q8 b
jta | thread | managed | custom.Class; y! ^, P5 P# ?
主要是配合
  m4 ^0 u4 }  g6 }: V6 E, SSessionFactory.getCurrentSession()' U3 d+ Q: n2 e/ K. ]
来用的.
9 x; `8 q- y0 r5 R1 _+ Z3 l. C" d7 ?Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
0 F5 R, I/ }7 k9 Y# U  F: n3 PWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
# b& a+ I" }% p8 a) B* I6 [context.BeginRequest += OpenSession;
9 d, M  U! G% A  l  J) U/ r.Bind(HttpContext.Current, SessionFactory.OpenSession())$ E# N; a5 M  {: n* P

4 i' |: m1 R3 Y) ~. D7 U//do transaction
+ @+ W& e: {6 x+ e4 }getCurrentSession().Submit();
1 K2 A9 y5 f8 h% e$ j: I& xgetCurrentSession().RollBack();
( W8 D4 A& n$ Y1 m! e. l...! b, P, a; o8 d, B* m
Unbind(HttpContext.Current, SessionFactory)
, f) J5 v8 z: C" T  q
" [& Z2 o. n7 c0 {& r0 acontext.EndRequest += CloseSession;
3 x3 \$ P( v, z7 O( Y
& _0 m& j+ z6 Z9 \/ X+ \( e7 ^8 n0 O 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-5-10 00:29 , Processed in 0.087689 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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