blogjava's web log

          blogjava's web log
          ...

          Nhibernate隨記

          在asp.net中.配置.NHibernate文件 ,
          web.xml

          ?? < configSections >
          ????
          < section? name ="nhibernate" ?type ="System.Configuration.NameValueSectionHandler,?System,?Version=1.0.5000.0,Culture=neutral,?PublicKeyToken=b77a5c561934e089" /> ?
          ??
          </ configSections >
          ??
          ??
          < nhibernate >
          ????
          < add? key ="hibernate.connection.provider" ?value ="NHibernate.Connection.DriverConnectionProvider" />
          ????
          < add? key ="hibernate.prepare_sql" ?value ="true" />
          ????
          < add? key ="hibernate.cache.provider_class" ?value ="NHibernate.Caches.SysCache.SysCacheProvider,?NHibernate.Caches.SysCache" />
          ????
          < add? key ="hibernate.cache.use_query_cache" ?value ="true" />
          ????
          < add? key ="relativeExpiration" ?value ="30" />
          ????
          < add? key ="hibernate.dialect" ?value ="NHibernate.Dialect.MsSql2000Dialect" />
          ????
          < add? key ="hibernate.connection.driver_class" ?value ="?NHibernate.Driver.MySqlDataDriver" />
          ????
          < add? key ="hibernate.connection.connection_string" ?value ="Server=localhost;database=northwind;uid=sa;pwd=" />
          ????
          <!-- ?add?key="hibernate.connection.connection_string"?value="Server=localhost;database=mysql;uid=root;pwd="/ -->
          ??
          </ nhibernate >
          ??


          asp.net 中Nhibernate Session 管理..

          using?System;
          using?System.Data;
          using?System.Configuration;
          using?System.Web;
          using?System.Web.Security;
          using?System.Web.UI;
          using?System.Web.UI.WebControls;
          using?System.Web.UI.WebControls.WebParts;
          using?System.Web.UI.HtmlControls;
          using?Ibatis.common;
          namespace?WebApplication1
          {
          ????
          public?class?NHSessionModule?:?IHttpModule
          ????
          {
          ????????
          public?void?Init(HttpApplication?context)
          ????????
          {
          ????????????context.BeginRequest?
          +=?new?EventHandler(Context_BeginRequest);
          ????????????context.EndRequest?
          +=?new?EventHandler(Context_EndRequest);
          ????????}

          ????????
          public?void?Dispose()
          ????????
          {
          ????????????
          //?Nothing?here????
          ????????}

          ????????
          private?void?Context_BeginRequest(object?sender,?EventArgs?e)
          ????????
          {
          ???????????
          ????????????
          ????????????
          if?(!HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.ToUpper().EndsWith(".ASPX"))
          ?????????????
          return;
          ??//?創建Nhibernate Session??????HttpContext.Current.Items.Add("nhsession",?ss);

          ????????}


          ????????
          private?void?Context_EndRequest(object?sender,?EventArgs?e)
          ????????
          {
          ???????????
          if?(!HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.ToUpper().EndsWith(".ASPX"))
          ???????????????
          return;
          ????????????????????? //銷毀
          ??????????//??INHSessionManager?mgr?
          =?(INHSessionManager)MindDumpContainer.GetInstance().GetObject(typeof(INHSessionManager));
          ?????????//???mgr.Drop();
          ????????}

          ????}

          ????
          }


          配置文件
          ???<httpModules>

          ????????
          <add?type="WebApplication1.NHSessionModule"?name="NHSessionModule"/>
          ??????
          </httpModules>

          3:

          ???加載 hbm.xml 實體

          ??? public NHSession()
          ?????? {
          ?????????? cfg = new Configuration();
          ??????????
          ?????????? foreach (string? entityName in 實體 程序集名稱)
          ?????????? {
          ?????????????? cfg.AddAssembly(entityName.Trim());
          ?????????? }
          ?????????
          ?????????????? factory = cfg.BuildSessionFactory();
          ??????
          ?????? }


          posted on 2006-08-02 10:09 record java and net 閱讀(940) 評論(0)  編輯  收藏 所屬分類: javadot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 香河县| 德惠市| 云龙县| 防城港市| 车险| 吉首市| 龙胜| 厦门市| 和顺县| 浮梁县| 射洪县| 三穗县| 绍兴县| 陇南市| 南投县| 湾仔区| 从江县| 余庆县| 仁化县| 泰宁县| 锦州市| 伊吾县| 西畴县| 中牟县| 涟水县| 图们市| 桦川县| 丹凤县| 新安县| 叶城县| 庐江县| 唐海县| 邵武市| 溆浦县| 平乡县| 穆棱市| 庐江县| 日照市| 双流县| 贵定县| 武胜县|