埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
/ N2 [+ W2 R# o# |
/ z" o! ~  A' k$ Q: N7 E1 S谢谢- p' f/ X/ d8 R3 _- I$ q

1 B5 Z4 H" ^4 N7 r0 x<property name="current_session_context_class">web</property>
# m$ w) A, F2 ?' N4 L# b<property name="current_session_context_class">call</property>, z! T3 ^. K) a) o& {
<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' x& }& a& {# Z
3 a3 \- w3 @3 ]9 pPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf9 Y; n6 a! ~: W1 `3 y

/ C8 l( C  x1 z. i# |. X- x+ E
9 _; ~6 g1 w: Y. y4 R+ h( QChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
& P: y$ k2 S: j7 C. D& t- V# N& `; l' y( M2 q

& ^8 O1 a  p- ^1 N$ U7 w5 XChapter 2.5 Contextual Sessions
, i' V$ B1 x1 ]; M$ V3 \. s$ S  L- Dgamahu 发表于 2011-7-14 21:56

( \# Q9 }" P2 P; i
8 {8 G, Q7 ]  o1 S$ ^; u5 ^谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.1 l$ |, D: T) u. M* C" d% r

1 Y% m6 f+ V- n! A& X' H, ^! C4 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
7 o8 c  ]& i2 }2 T; X; x( e基本参数:$ c  e& f9 o7 @( E& G
jta | thread | managed | custom.Class
! O- U1 M7 T0 h) E$ C主要是配合2 O* p, m; m) Z* n' A  h0 f' ~3 f' g
SessionFactory.getCurrentSession(): r, X! }1 a# Z5 y0 v* F
来用的.
/ G/ U' l! D# J, b; LThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,3 \) P+ a1 j2 K  e, I
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:& T1 I3 C' u8 x4 F" H, ?
context.BeginRequest += OpenSession;
% i$ R1 L7 D8 Y  `3 z# y3 e+ `.Bind(HttpContext.Current, SessionFactory.OpenSession())
" ~* p4 d$ ]8 J/ P* F/ `: {+ V+ ~. E* ?( F! p
//do transaction) C% R$ M# }! ~  `2 V
getCurrentSession().Submit();. f- Z% O- A( x
getCurrentSession().RollBack();
0 X: @# [+ U3 Y' j6 x* O: ]5 d. X0 m...
" m2 h7 [1 |4 B& R* b0 Z1 fUnbind(HttpContext.Current, SessionFactory)
6 k7 G7 M! J6 u+ m0 h- Z" \9 F" N- {7 }; q5 V7 m
context.EndRequest += CloseSession;
: B7 U; r! b/ R0 o" G$ i0 q" Y: h2 _: S9 V! E6 \1 I2 d7 a
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-3-25 19:12 , Processed in 0.132175 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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