埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
+ A, L  u! X& B% ^' F- k" Q+ Z5 N3 u% j
谢谢2 ]) x0 c/ P+ A5 T: r

( H& U  J- H7 U<property name="current_session_context_class">web</property>( E* j- n$ P! w1 y" H; W/ D
<property name="current_session_context_class">call</property>  B6 d; T5 j& G+ a7 P& x6 Y
<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 编辑
" {  D9 W4 m  l+ \7 N7 [9 |8 b# [, x# K* I$ R/ N, }' S5 y* a9 n
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf% g# l8 N0 @! j! V5 D5 ?: ]! T! b

9 r- i+ y) ]9 Y) L/ Y2 s. E) j. U# N0 g3 g
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf$ D: ~& A  F6 p6 q3 Z& k) }: j/ v

0 L. F* |! r$ W; `
( O% l6 G/ q( s0 d0 nChapter 2.5 Contextual Sessions/ S6 S& d8 F' d( S6 o. _
gamahu 发表于 2011-7-14 21:56

; d- w- V9 K# k/ G" c9 d
" H4 b! O$ R. k谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
+ E' B+ `* }* M4 u9 d
* ?5 @4 X( I$ W& ]5 ?, o现在还多了个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
0 U9 ?+ v6 {; W8 f基本参数:1 C( P  w0 `# W- [5 c
jta | thread | managed | custom.Class
4 x2 V1 _0 V0 A' X" D5 m0 ~主要是配合
) q5 T+ P4 T/ Q) L; g+ A* _8 hSessionFactory.getCurrentSession()
0 I& y6 [( f; K; e* D来用的.2 t) P/ x1 O8 n( C4 Z5 h9 z; x& `0 f
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
1 h% c" b4 r! S+ s- \1 nWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:- @5 r# t; Q; ]
context.BeginRequest += OpenSession;( l& b) g' u4 n
.Bind(HttpContext.Current, SessionFactory.OpenSession())- W5 D+ q6 l( _1 S3 c4 }( C- g
- L5 _$ ~$ ~  j5 [4 l& G5 M  W+ w* ?( c
//do transaction1 F* S  D6 x7 k7 u' o
getCurrentSession().Submit();
7 h% T' ?$ o% x- EgetCurrentSession().RollBack();5 Z* Y/ C! F" ~- {8 Y( o* J$ G1 X
...
5 P8 Y' ]' {% D: q1 O( hUnbind(HttpContext.Current, SessionFactory)
( A8 t: R3 ~- t2 D% \  Y6 z% l$ d) k* t
context.EndRequest += CloseSession;. O: w. m7 M2 R2 H

; u: {( L$ I: l, @% e' @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-18 21:25 , Processed in 0.119033 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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