埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?. u+ C0 \$ \, K/ X" P
+ K4 {1 ]; k. T$ r
谢谢
4 ~+ \$ E" ?' S& ?: S0 @5 O
% D2 R' _) S# u& m: j3 H" t% C& n<property name="current_session_context_class">web</property>
: U4 L, q! G0 q8 t! G# b<property name="current_session_context_class">call</property>$ c) V, p* I) x) Z3 t
<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 编辑 ( [; D9 c! s2 y9 ?1 n
, a% T4 S5 N* m" X5 m+ I, }5 P6 a
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
8 I& W8 Y1 @  F* W  b$ G& h$ I" L/ M7 ^; X

/ S0 g) p* h9 E+ e: D5 CChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf9 M" _- {  Y3 s( ]- i% w

9 o  r1 K- }9 r# E" f4 v+ t# J3 ~2 `3 e; _: ]
Chapter 2.5 Contextual Sessions! H6 G; q4 M* q4 `# b6 z
gamahu 发表于 2011-7-14 21:56

/ |1 Q5 \/ e$ x  F) D! \* W3 z8 n; d* H. S
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.! |. d" y: ]3 `( L3 |- k, U

- F3 {) M9 s5 M7 }! P1 @2 S1 ^现在还多了个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# H' W4 Z& u2 C/ {
基本参数:! J8 P/ W/ C0 T3 l
jta | thread | managed | custom.Class
1 F: ]) Q) g2 w7 `' g6 g! j1 T主要是配合$ W4 o1 f$ C' h8 F
SessionFactory.getCurrentSession()
% b' P& ^: U5 p% [来用的.% l. r5 }, f$ c4 B
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,6 ^/ D$ L9 q! }, r
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 M* D+ m  V( z7 g. ]+ Ycontext.BeginRequest += OpenSession;
/ H  d0 ^4 J0 y: V# y.Bind(HttpContext.Current, SessionFactory.OpenSession())5 C4 g' K, B& g" b3 |! f6 f4 T
6 ^# |1 t9 Y( A$ \# o5 ]8 _
//do transaction
" q8 n9 t9 d& [6 D) ^7 z, Z2 x8 IgetCurrentSession().Submit();' W' ?' y. O0 t2 w# `
getCurrentSession().RollBack();) l7 Q8 V1 l0 [1 ]# w7 d% P, s0 g( L
...
0 Z9 _! {2 F# Q2 }4 D" CUnbind(HttpContext.Current, SessionFactory)( P1 y% u; k, X: [

! E" H3 k! a! B0 o1 Scontext.EndRequest += CloseSession;
  `" }1 E9 f  e3 l& y6 y4 O! F; W2 F5 Q, q3 P* p5 f
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-10 08:46 , Processed in 0.141049 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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