埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
6 _" y1 |1 t  U7 Z0 b$ S2 B# C
3 W+ q; C' {& B% |: ]7 U8 H谢谢
6 Y" p+ c) l1 v7 g) N' X5 b% I/ W
<property name="current_session_context_class">web</property>
; D0 L+ o/ H8 w<property name="current_session_context_class">call</property>
5 p6 @  R) Z+ a8 ^: ]<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 编辑
# L" N8 @# q2 t/ M
2 Q! M& `* m% A$ wPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf" \5 k- L- s% t( m# m4 ^. k

! Q3 |4 i1 p4 Z" m" r+ c& d6 g& R$ Z0 Z% g% v: x% `
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf+ I- p9 G! b2 [7 A
- \* |+ t9 F8 x

6 ^9 v$ c4 H0 I) c, ^Chapter 2.5 Contextual Sessions
! V) N2 F9 e$ L& D( l5 _gamahu 发表于 2011-7-14 21:56
* Y9 V+ j+ a& U
  q9 K3 r; p9 i) J
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.. h3 c& e7 p* ], F
" \- G4 y/ u7 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
- w5 F( |: b- C7 [; V' z7 X基本参数:0 K( s5 Z8 @( A, e  s
jta | thread | managed | custom.Class( s6 h% m& u8 t0 O  |. y) H
主要是配合$ D; U7 P8 E0 d* Q( U/ }
SessionFactory.getCurrentSession()
9 l+ r) v& K5 ?( U来用的.6 {4 `" ]0 @5 L) `' |
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 [. w$ f  {" c9 W3 [) A4 pWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:. q2 M- k5 W  m+ t) D2 k
context.BeginRequest += OpenSession;# b+ \1 @% J/ E3 D
.Bind(HttpContext.Current, SessionFactory.OpenSession())
; L7 F% @6 Q; L0 m
! p% r2 D& \, `7 U//do transaction# S& m0 y, _% D5 A) p
getCurrentSession().Submit();4 Z% c$ P) v( @8 m
getCurrentSession().RollBack();
0 D6 y$ W" [& q9 C. m' L...5 y* L( @, Y  K; P0 ?6 ]: t
Unbind(HttpContext.Current, SessionFactory)
4 q2 `2 [, c2 @
& b" j5 c; g) M0 w0 P2 Ucontext.EndRequest += CloseSession;" Y2 u6 |0 ?* U) o

1 f/ n% W; Y2 O; O7 a 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-2-23 17:37 , Processed in 0.147530 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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