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 閱讀(936) 評論(0)  編輯  收藏 所屬分類: javadot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 轮台县| 牙克石市| 达拉特旗| 丰原市| 富顺县| 文昌市| 竹北市| 和顺县| 武安市| 布尔津县| 视频| 汝南县| 武夷山市| 长白| 桂阳县| 英吉沙县| 广东省| 河北省| 仪陇县| 吉林省| 琼结县| 肥乡县| 扬州市| 聊城市| 南投市| 定兴县| 云和县| 宜黄县| 拉萨市| 宁强县| 景谷| 阿坝| 琼结县| 岐山县| 始兴县| 张家界市| 洛阳市| 新河县| 西吉县| 固始县| 扎鲁特旗|