埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
& y5 F: f# ^% R3 h( {. l4 M7 X% Z) V" x
谢谢; D! M- K- S1 r  Z' k! O
0 e: J" J; ~) }
<property name="current_session_context_class">web</property>
9 K! V! ]+ {  y1 o" D! l" _) u<property name="current_session_context_class">call</property>
2 @* t% T+ f2 j6 H4 {<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 编辑
  F; A5 j; z. X1 o/ @  q
  v1 }8 p9 g+ |. I; z2 q( rPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf: _0 g; e' d" s; t0 f1 ?
3 e( H7 R9 h) d6 l8 D/ R5 g

' ]  J# I. O0 u; i5 kChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf8 j& h6 a- @" V$ w7 e0 O

; V) l/ ]  x6 I, D* b1 I! J" C( O4 L$ w9 R
Chapter 2.5 Contextual Sessions$ M) ~+ Z. u* m
gamahu 发表于 2011-7-14 21:56

& ~. ]; f1 n2 P2 c( A! s4 C; |" C+ b2 P' q& T% k
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
; R. v8 b" Y: Z% E' k  L  `4 D5 z' h
0 \9 }4 D1 q( g4 N$ {% I0 j: b& ^现在还多了个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$ |! Z9 L$ ^7 D, c$ C2 o
基本参数:  p# o' o  w- B& `: A/ J8 e+ s
jta | thread | managed | custom.Class
5 A% S1 [( E' h3 q; G* X  i主要是配合8 {9 @0 F( @1 I9 ~+ L+ D7 @, V7 i+ U
SessionFactory.getCurrentSession()' m1 P1 h: X' @4 z
来用的.
+ D8 `& l8 g% y+ ]# I( e$ I. GThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 H5 f: V( X. y4 r9 ?Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
( c5 ~( t+ s" E4 ^/ Ocontext.BeginRequest += OpenSession;
: g* Y1 `7 C$ s- l/ N.Bind(HttpContext.Current, SessionFactory.OpenSession())) j9 _, [- d. a9 f6 A5 q6 i
0 H7 k0 L+ @  D) s( @+ U. E
//do transaction
0 p+ k% b& a" ^; LgetCurrentSession().Submit();
$ Y/ G; I) I7 j! u6 OgetCurrentSession().RollBack();7 |# T. ?# B  o, J* B& t3 {7 A
...
( |$ ^# l5 u$ l/ I9 a% d7 Y6 m4 }" d6 IUnbind(HttpContext.Current, SessionFactory). D* p8 \+ b( k  U
  s4 ~5 ?6 u/ I2 C" L' U' F
context.EndRequest += CloseSession;# D" s  @8 T& M# v5 |
0 o4 C- a- K) s/ |
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-2-23 11:06 , Processed in 0.249293 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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