埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

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

7 |% @9 x& i  |& b- j5 b: i  \谢谢5 p# S' ?) ^* |# y; A, o7 O7 l5 o

- F' [6 E4 v5 S3 g3 X" ^: U<property name="current_session_context_class">web</property>
" |' s4 e9 X; o; O( u7 Q<property name="current_session_context_class">call</property>4 }: [( V2 y3 j
<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 编辑
1 v1 r) v; M" H- h% u; q/ n- s# A5 ~. H8 M$ F5 {
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
' q, o; i7 ]' D
* P* s2 N1 `# E  q
9 \/ W3 `9 ]0 k. ^, Y+ qChapter 2.5 Contextual Sessions
理袁律师事务所
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf% ]$ V8 z1 W" c  p4 N# a( l, S' D
# s/ E/ m4 t2 @. P% Z8 l; Q! j
9 h5 f( ?1 w( r
Chapter 2.5 Contextual Sessions& e* u# I5 ^" M1 G: K1 w
gamahu 发表于 2011-7-14 21:56

) J, L3 R( g! i$ Z- J1 i4 D; ~: C! I4 ~' t( L  ], M4 t
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.* r* L9 l/ f! y1 A2 W/ P4 `3 z

3 i; s7 ^1 V- K* O/ }现在还多了个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
  b" J  O1 E1 Y7 A8 {基本参数:
! E; t* d. ]( Y6 _jta | thread | managed | custom.Class
: y4 H8 ]" i/ G. _- X. s0 M主要是配合
# `8 U# @: X/ }2 f  s8 xSessionFactory.getCurrentSession()8 |5 {5 v: ~, Y4 m- p: L: x
来用的.7 n9 n( z, H6 g7 I" [
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
" V" h0 I7 _$ `- h$ J/ XWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
# {# F7 C3 {. b. N0 ^context.BeginRequest += OpenSession;
% R% o0 B, x3 g.Bind(HttpContext.Current, SessionFactory.OpenSession())
  z) O! {/ B% o. ^6 x
* A, ]7 E; e$ {6 u  {1 t//do transaction
8 E0 ?7 c2 E% ?2 e$ fgetCurrentSession().Submit();! a+ k, `5 E9 A& M7 |* B5 S
getCurrentSession().RollBack();
$ U4 z; U3 i9 W1 F0 M7 D...: ?- w0 n( p9 |+ h
Unbind(HttpContext.Current, SessionFactory)
# B( F% A' x/ F/ E$ {
$ Y* t, v" l* u1 e- D% W; Pcontext.EndRequest += CloseSession;3 O9 I. M2 h6 |2 L5 M

: s2 C: z" ?! ]6 z4 i3 z* b 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-5-10 08:22 , Processed in 0.146979 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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