埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
2 z  S  z- ^' a, `
5 k0 f1 f2 {; p/ Y. M5 P5 f谢谢
. C3 e2 k) o/ u5 I7 F1 ]3 U3 i# S6 A( u& K$ _6 \/ W& t4 r/ V& \
<property name="current_session_context_class">web</property>
" f- f( t; e, d. m<property name="current_session_context_class">call</property>* f8 _3 }6 f5 @1 k0 @1 U$ \8 @1 E
<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 编辑 - n' o  A: Z3 {/ E9 z% I$ H9 P8 R# I
6 u% l  ~% `; d! {1 c
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
6 f3 S" \* |: {3 }4 `
' |% m1 d0 \4 v& n" |7 e  X, i7 L0 _8 X& @
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
1 M0 M% \: z0 P; A2 W3 F' J% K- `& g- V4 j5 r% j5 K

& @+ i  k, s! EChapter 2.5 Contextual Sessions
" Z9 X; E& r, W2 A8 r* W3 ~gamahu 发表于 2011-7-14 21:56
# h6 O9 M" h9 g  z

/ x! y  |5 s- w7 M3 H4 w) {谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.+ i6 _: }  f8 s, R& j) ?
7 V! y" _5 Y/ g5 J0 u7 j
现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what3 l1 k" G7 Y, e0 F
基本参数:
/ a" N3 D$ N$ ljta | thread | managed | custom.Class
4 q4 G- Z% z, S: f" A: Q8 G主要是配合
* [# D# D4 J+ b2 Q" ~) _; nSessionFactory.getCurrentSession()9 u- r0 E, f! I) `% D/ E/ U
来用的.5 J' L) k$ `; @* t1 ]
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,% q5 b  Q5 ^4 f" [6 a
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:% r; |! v- F% W4 a; ?' Y* U! U  Z
context.BeginRequest += OpenSession;
8 f+ i, W) C0 \# O.Bind(HttpContext.Current, SessionFactory.OpenSession())' K' o; Y3 M- o' o
5 P- H3 ~+ _% b$ S; n
//do transaction) y" V0 L4 X; m/ _& O$ q5 s) c6 J
getCurrentSession().Submit();
; b* n+ C  y2 [& E* bgetCurrentSession().RollBack();
# y' \' o1 e* H7 ]* V, s...: b3 O/ D* u$ C0 Q8 M7 K( Q/ n; c
Unbind(HttpContext.Current, SessionFactory)
! q, `% `1 Z) [5 v) T/ D: e2 ?2 J, c# X) @2 v9 @9 X
context.EndRequest += CloseSession;0 E5 `* W1 Z" [5 ^* {
- S7 E! b1 N% h1 W$ k$ W
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-4-23 20:49 , Processed in 0.187897 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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