埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
# i' ^1 }7 R! O3 e# I+ L4 k; P
. F- G6 K3 W: ^0 r谢谢
: a/ D6 p4 V4 q3 D; ?/ ]8 O$ V# g* k8 X
<property name="current_session_context_class">web</property>
$ K7 L5 n: _" d<property name="current_session_context_class">call</property>
# S& S1 Z3 Z1 ~, x; C# X0 m<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# e/ c4 _; [: K8 S% F3 m
* j% m- \$ K. e8 w, H$ ^5 N% ~Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf2 m2 A2 g8 P! V+ V
; I2 s2 Q! P0 K4 H
. Q+ {% b3 h* ?: B# H5 Y! T
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf" W- u' d+ }- C

$ P1 X# \" P& l1 B" J9 V. i5 a' ]  x7 J! O1 D
Chapter 2.5 Contextual Sessions% K% k( E# t* a8 ]" r
gamahu 发表于 2011-7-14 21:56
: p5 g4 J0 s8 t" h: p
% g5 L8 \% s( p% c0 D' N
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
" f8 q9 p" W9 F% {- \+ B- C
2 n& F7 M; H7 }6 e1 \( r; ?现在还多了个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+ U- A% F9 d$ `
基本参数:% h: |* R7 S+ E8 k+ a& Q
jta | thread | managed | custom.Class, f, m4 m. t9 z6 U
主要是配合) p+ E5 y) x7 J, o9 j' G3 O7 z1 G) T
SessionFactory.getCurrentSession()- X6 |' L& l4 F% c. g
来用的.1 R9 l5 @" I  u* N+ I$ n
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,% u( [& u% A7 O/ Z
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
$ \, k/ s5 o& n" v+ t/ d! ccontext.BeginRequest += OpenSession;4 w* L: E) f1 q& d$ R& h- q, r
.Bind(HttpContext.Current, SessionFactory.OpenSession())! \0 s  e1 K% s/ B
( Z! r! }5 ]) e( ?! S
//do transaction
" y/ p4 g8 [1 f1 y% n, _getCurrentSession().Submit();
7 ~& x- r  k3 i! MgetCurrentSession().RollBack();- w* e, C6 L; T
...- X, o2 J0 O  Y- [# L% t% `
Unbind(HttpContext.Current, SessionFactory)
" _! P" l6 A# G+ d* q
; M% y. j5 B2 ]6 p% ~3 S$ Y3 Jcontext.EndRequest += CloseSession;  P8 n* V+ Y5 [! m! \

% s! b( ^4 v1 a$ E8 f) l 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-3-15 02:33 , Processed in 0.123320 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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