埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?+ a  |1 q: {2 ]+ O

% h  h4 K* M% N8 {- L- c# D; [谢谢  g8 o2 r" g, e- R

' L  U; Q2 ~1 r2 D* y% l+ V<property name="current_session_context_class">web</property>- ], v2 T+ c$ _* i) P! i9 b3 a  @* x
<property name="current_session_context_class">call</property>+ _& G5 c% _# \5 j, p
<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 编辑 . R8 R, P4 @& U  Y5 R( s5 Z; X

, p1 M' m9 E( k" ~4 j, Q; MPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf6 {0 m0 X2 ]# n1 U  ]

, ]+ `1 c$ D8 R. u9 a5 z9 c
3 _3 Z" b0 S8 t& n% ~0 Z4 CChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
6 }) G3 e2 }+ p& {2 t" \! X* q; v# s$ {3 m% v% |
* E7 V# L; h2 V3 k$ D& {; b. R" H
Chapter 2.5 Contextual Sessions
; j+ _  s! `/ s2 [* ~0 Vgamahu 发表于 2011-7-14 21:56
' @- Z# i$ z4 l& Q2 d7 V2 K

/ [% T3 Q4 a8 Q% {谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
1 G! |5 w2 `5 O. h7 Y
: ^- y. F. u& p+ [+ I/ 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 what2 j+ {- [$ \, G2 m7 E, H  c) q" `
基本参数:3 F( J7 n# }9 {+ d% Q! f5 V% K
jta | thread | managed | custom.Class' K, \& e/ }2 `. X. Y0 Q& E" ^
主要是配合3 o) e3 R5 H4 Y! ~# {
SessionFactory.getCurrentSession()
  T0 r2 H$ Z- _9 q' v/ v/ H来用的.$ a  e; P1 D. J: c/ {4 j: b
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
! M/ t* ]: h+ x, w4 h3 A2 qWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
+ X; w4 J* y/ }* D7 t7 gcontext.BeginRequest += OpenSession;' S3 n! s3 l: N9 M
.Bind(HttpContext.Current, SessionFactory.OpenSession()), c6 a: z) o( U: M
! e0 l9 o1 z& B
//do transaction9 g7 E* u6 U3 q+ G$ M# N
getCurrentSession().Submit();
9 v; z' J0 I: p' UgetCurrentSession().RollBack();
8 F7 t" K9 c4 E" T, l: f+ m...
3 G* m- W" B( }0 OUnbind(HttpContext.Current, SessionFactory)
/ o" l! b9 h! {) a( o9 o8 D: k5 x: C& K& b4 a# z
context.EndRequest += CloseSession;1 h: D8 }, o" o1 _3 E0 {

; [" u0 b2 D4 O) m! m& ~ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-9 18:25 , Processed in 0.103110 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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