埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
/ g% g9 W$ g/ ^! o
5 g+ a" s+ I* a9 T谢谢
8 {! ?5 w' q. c/ J1 S, T  ]$ f
<property name="current_session_context_class">web</property># [7 J$ L* t1 n5 Z  ?" g# _
<property name="current_session_context_class">call</property>- O4 _) \+ |  Y. X' t! \, 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 编辑 . I5 }9 c4 G% v8 W
! p) T/ e2 \+ Z1 u6 ~
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf4 V6 c% s+ `6 o

+ d- V) [- R& {3 k7 ^3 q+ Q3 V( Y* h: n* k( `
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf7 a  P; p  }- }- b$ w2 v1 b) F

" {( s) i3 d2 h; S  ~+ ]
, x  h  U, E! x5 SChapter 2.5 Contextual Sessions
  J7 m1 D3 }  w, s1 H/ a6 T' F2 ?gamahu 发表于 2011-7-14 21:56
# \) a: M- j) R/ V" m; y

! n2 J5 I$ e" v; `谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
6 g( k! m; h) a+ k. ?
0 ?; z& K: {& K) l( N现在还多了个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
+ V5 V& M& I; n基本参数:# T; F! S* j9 b& E5 C, R
jta | thread | managed | custom.Class8 p( N0 P. ~- a4 N
主要是配合
7 B0 f5 R3 }5 O; q9 q  v. m( hSessionFactory.getCurrentSession()
2 r, p( e! q. ~" F, @$ s来用的.
5 D3 x) j  o8 P) Z( GThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 u; W, Y+ w. C6 f4 q( cWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
3 K3 O! s! m8 E5 g2 j1 h; B) }context.BeginRequest += OpenSession;
& b) Q3 u) e/ p: g$ I5 L.Bind(HttpContext.Current, SessionFactory.OpenSession())
! T/ d9 b7 W- Q7 n' D
8 l% I/ E" E: r0 \9 e3 t//do transaction
$ l1 A# j, `3 `( n- f0 M; IgetCurrentSession().Submit();
1 T0 O" f4 m6 f( V. N2 ggetCurrentSession().RollBack();
$ n. _6 s5 a! i4 }' V6 M: X& m...* a- `, u0 G/ [" ]0 p: [+ l% |
Unbind(HttpContext.Current, SessionFactory)
% d/ o: Q1 Y1 S$ V4 s" M* w5 d
( W$ A' C* |6 Z. [' Wcontext.EndRequest += CloseSession;
8 ]4 r+ P) T6 H% j4 [  G
2 T/ U4 L( D3 n6 A0 p- L; ~6 E$ p1 T* ] 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-8-24 19:14 , Processed in 0.169438 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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