埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?5 ^8 n3 y4 C6 H
" x% O0 }' w, ~2 N+ C9 ]3 b) w
谢谢2 I- h& _* R& i0 n3 {5 |, y# g

% P2 _- l  H  c) t: R- r1 f<property name="current_session_context_class">web</property>7 _9 ^- T/ q8 \4 {! ^
<property name="current_session_context_class">call</property>
& ^- W0 S; s1 \% q. R. F<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 编辑
# i  \3 P* Z/ g/ \1 q- S2 x8 ~$ v1 f& y
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
, I) [9 D0 H0 t, \/ n" l! H9 d& J( |$ l5 ?+ X- K4 D

' z; ?7 C' I- g6 }$ ^* J0 l* h3 pChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
) p7 Z) C2 ]9 M2 r1 z1 L+ o7 J. b' I+ `

9 y7 G+ a1 s0 _( U( ^; x8 `6 Z, vChapter 2.5 Contextual Sessions
+ o( J2 _( |" |- U9 fgamahu 发表于 2011-7-14 21:56

2 j9 m& a7 m2 |! e1 D- ]
5 o$ c/ n* w7 L谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
3 f+ v' w. h' Q2 f$ t) ~! i* g  b( @5 y2 U1 {( p9 d
现在还多了个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
1 I7 c+ @: ^8 u, K- j基本参数:
' S+ c% U- ^7 G. R* ]jta | thread | managed | custom.Class
, H) q2 r2 |( A- J5 D: D: |* y主要是配合
( b9 |0 {; X8 Y" m9 z4 e0 fSessionFactory.getCurrentSession()
9 n! |3 z5 ^3 k来用的.
" w0 p: v' K$ A( T6 sThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 }) e- O) S' v* \: A! a% t# XWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
& _; {( Q" V0 w5 i2 wcontext.BeginRequest += OpenSession;
2 B+ a7 p9 k4 g2 j5 k4 a.Bind(HttpContext.Current, SessionFactory.OpenSession())* ^7 c( c0 I5 G1 ~" u" h& H7 u( P

2 |3 y  C: c1 X/ Y4 B$ p//do transaction6 R" k! Q) F( x, ^3 i) Z
getCurrentSession().Submit();8 J' H  ?& }9 D4 f# e% i
getCurrentSession().RollBack();
* V% Y+ x* {& @7 x/ Z  v..., O; s) b2 |8 x1 v* q
Unbind(HttpContext.Current, SessionFactory)1 {! k. C, K# i; ^# c) Y7 N) p
9 [8 n  ^# W. K& U! m) w0 }) f# A* X
context.EndRequest += CloseSession;
& j  Q1 W* I( v) @9 {1 U% M3 }  r: ~2 o: f2 b. q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-4-25 17:28 , Processed in 0.141966 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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