埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
/ z3 c, V( O9 G6 P+ o# |7 V5 d
7 w% m, n3 R( _( l4 f谢谢* U4 D  Z2 s( s

( H. q, ?. a! g" d/ K5 @<property name="current_session_context_class">web</property>
; v; D4 u3 k) l0 b<property name="current_session_context_class">call</property>. M% I: ^2 n! v" }+ @
<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 编辑
  C$ s; {, F& @
- r. ^! A% e1 A/ e: v0 EPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
* I  y! r& ]5 J7 Y  M. a: Y9 A& S8 J

( A' S3 ^4 H5 OChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf1 j( k2 b( D7 e

& R+ m! K5 r; W. W# F
# g7 x7 E/ Y! b: s1 }% D5 oChapter 2.5 Contextual Sessions
8 @; y2 a7 X7 a8 L- ?- b& k: |gamahu 发表于 2011-7-14 21:56
! d3 v& S; q/ x* I; A; M# U
9 {' n7 c& v% L4 R
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
& }% L. J* N5 L6 F1 q% G
9 U3 }" X0 O; F现在还多了个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
+ t3 D) j! L/ X9 L& N基本参数:
, [5 Z$ e9 W/ l4 E: t7 jjta | thread | managed | custom.Class8 @+ r  s5 |5 m
主要是配合
5 c& R6 R+ o5 w* C6 R. QSessionFactory.getCurrentSession()0 }( A# C% Q* m  S$ o
来用的.
& \4 d1 a- J/ hThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 m# q2 r7 q" b6 q9 J4 mWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
# g2 q( j! e. l2 e; Bcontext.BeginRequest += OpenSession;
6 n9 l' f0 p+ V8 Y.Bind(HttpContext.Current, SessionFactory.OpenSession())
8 s6 E  P! X1 s+ x6 y  Q0 K4 }/ c2 G! b" ^% ^0 A- A
//do transaction  \% a8 y; Y6 p6 u6 t
getCurrentSession().Submit();! O  {0 F+ Q$ y$ T' q
getCurrentSession().RollBack();
5 A: w# ^6 R7 W5 a( E  T...8 ^0 u0 f# S5 K) x& f
Unbind(HttpContext.Current, SessionFactory)0 f4 Z# V, Y7 }
/ L# g0 ]# Z7 U0 E; S' ^* S
context.EndRequest += CloseSession;4 [7 K9 V2 e0 I6 Z5 b8 V+ J, U
8 W) b& m  I; I- a6 N, m. Z% f! q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-18 03:54 , Processed in 0.140457 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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