-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Pls Help Web.confif File Error in .Net with Nhibernate
PostPosted: Tue Jun 23, 2009 3:38 am 
Newbie

Joined: Tue Jun 23, 2009 3:07 am
Posts: 3
Hello EveryBody.
I am new in Nhibernate with Asp .Net.


MyFolder Structer is
in D Drive :
D:\online\OES
in this some folder like
OES.DAO---it is a Class libabrary
OnlineExam---It Is website in Asp .Net
and My solution File OES.sln

Tecnology used is VS2005,Nhibernate,Asp .Net,AJAX
I develope A Arcitectuer in which two layer .
One is website layer and one is my Class libarary whic name is OES.DAO.
OES.DAO CONTAION ALL BUSINESS logic.
Image

OES.DAO CLASS LIABARY CONTAION SOME FOLDER

ONE OF THEM IS
1.dblayer: it contaion one class
which code is

Code:
using System;
using System.Collections;
using System.Web;
using NHibernate;
using NHibernate.Cfg;
using Iesi.Collections;
using OES.DAO.businessobjects;
using OES.DAO.util;

namespace OES.DAO.dblayer
{
   /// <summary>
   /// This is the main class for accessing the database via the NHibernate O/R mappings.
   /// The middle tier should use this class for DB access!
   ///
   /// The usage of this class is along the lines of:
   /// 1. Call BeginDBWork() and use the session it returns for DP operations
   /// 2. Call EndDBWork() - commits the transaction frees resources etc.
   ///
   /// The above methods are to be called by the application at start/end of
   /// processing a request. Individual ASP.NET pages are expected to use
   /// GetCurrentSession() to work on their data!
   ///
   /// </summary>
   public class DBFacade
   {

      private const string SessionHTTPContextKey = "itexampractice-context_session";
      private const string TransactionHTTPContextKey = "itexampractice-context_transaction";
      
      private static readonly ISessionFactory sessionFactory;
      
      private static readonly bool runningInMonoOnUnix;
      private static readonly bool runningInMSDOTNET;
      
      /// <summary>
      /// Initialization method for the DB facade. Gor now it is a dummy since the static
      /// initializer does the work
      /// </summary>   
      public static void Init()
      {
         // ...
      }

      static DBFacade()
      {

         
            [color=#FF4040]sessionFactory = new Configuration().Configure().BuildSessionFactory();[/color]          Log.Info("DB Facade being initilaized, Platform: " + OSInfo.PlatformName);
          runningInMSDOTNET = OSInfo.PlatformIsWindows;
          runningInMonoOnUnix = OSInfo.PlatformIsASortOfUnix;
         
          if (runningInMonoOnUnix)
          {
             // TODO: Maybe special init code .. if necessary
          };
      }
      
      /// <summary>
      /// Opens a new session for woring with the database. At the same time starts
      /// a new transaction. The session and transaction are saved under the server's
      /// HTTP context. The session object is returned for subsequent operations
      /// </summary>      
      public static ISession BeginDBWork()
      {
          HttpContext context = HttpContext.Current;
          ISession currentSession = context.Items[SessionHTTPContextKey] as ISession;
          ITransaction currentTransaction = context.Items[TransactionHTTPContextKey] as ITransaction;
         
          if ((currentSession == null) && (currentTransaction == null))
          {
              currentSession = sessionFactory.OpenSession();
              context.Items[SessionHTTPContextKey] = currentSession;
             
              currentTransaction = currentSession.BeginTransaction();
              context.Items[TransactionHTTPContextKey] = currentTransaction;
          } else
         {
            // TODO: Close sesion and transaction
            
             // No current session
             throw new SystemException(
               "It seems someone is trying to open an NHibernate session, although " +
               "one is already open!");
         }
         
          return currentSession;
      }
      
      /// <summary>
      /// Returns the previosly opened session. Throws exception if it is not open!
      /// </summary>      
      public static ISession GetCurrentSession()
      {
         HttpContext context = HttpContext.Current;
          ISession currentSession = context.Items[SessionHTTPContextKey] as ISession;
         
         if (currentSession == null)
         {
            // No current session
            throw new SystemException(
               "It seems someone is trying to get a NHibernate session, although " +
               "one is NOT currently open!");
         }
         
         return currentSession;
      }      
      
      /// <summary>
      /// Starts a new transaction within the same session. May be used when we have
      /// processing spanning several transactions.
      /// For convenience returns the session.
      /// </summary>      
        public static ISession StartNewTransaction()
        {
            HttpContext context = HttpContext.Current;
            ISession currentSession = context.Items[SessionHTTPContextKey] as ISession;
            ITransaction currentTransaction = context.Items[TransactionHTTPContextKey] as ITransaction;
         
         if ((currentSession == null) || (currentTransaction == null))
         {
             // No current session
             throw new SystemException("Starting new transaction but no session exists!");
         }
         
         currentSession.Flush();
         // TODO: This is a workaround for problems with Mono and ADO.NET
         // transactions. The bug is expected to be fixed in Mono in early
         // 2008!
         try
         {
            currentTransaction.Commit();
         } catch (Exception e)
         {
            if ((!(e is NullReferenceException)) || runningInMSDOTNET)
            {
               throw e;
            } else // NullRef in Mono
            {
               Log.Warning("DBFacade: Ignoring NullReferenceException - " +
                           "Workround for a Mono bug (versions prior to 1.2.6) " +
                        "with ADO.NET transactions!");
            }
         }

         // Start a new transaction here
           currentTransaction = currentSession.BeginTransaction();
           context.Items[TransactionHTTPContextKey] = currentTransaction;
         
         return currentSession;
      }

      /// <summary>
      /// Ends a previously opened session. Commits the current transactions and
      /// closes the session.
      /// </summary>      
        public static void EndDBWork()
        {
            HttpContext context = HttpContext.Current;
            ISession currentSession = context.Items[SessionHTTPContextKey] as ISession;
            ITransaction currentTransaction = context.Items[TransactionHTTPContextKey] as ITransaction;
         
         if ((currentSession == null) || (currentTransaction == null))
         {
             // No current session
             throw new SystemException("Ending DB work but no session exists!");
         }
         
         try
         {
            currentSession.Flush();
            // TODO: This is a workaround for problems with Mono and ADO.NET
            // transactions. The bug is expected to be fixed in Mono in early
            // 2008!
            try
            {
               currentTransaction.Commit();
            } catch (Exception e)
            {
               if ((!(e is NullReferenceException)) || runningInMSDOTNET)
               {
                  throw e;
               } else // NullRef in Mono
               {
                  Log.Warning("DBFacade: Ignoring NullReferenceException - " +
                              "Workround for a Mono bug (versions prior to 1.2.6) " +
                           "with ADO.NET transactions!");
               }
            }
         } finally
         {
            context.Items.Remove(SessionHTTPContextKey);
            context.Items.Remove(TransactionHTTPContextKey);
            
            // TODO: Close the session in any case - to start clean!
            currentSession.Close();
         };
      }

      /// <summary>
      /// Releases all NHibernate resources for DB oprations. To be called at the
      /// exit of the Web application.
      /// </summary>      
      public static void CloseSessionFactory()
      {
          if (sessionFactory != null)
          {
              sessionFactory.Close();
          }
      }
      
   }
}




Here I Got Error sessionFactory = new Configuration().Configure().BuildSessionFactory();


2.Thesecond FOLDER in OES.DAO IS businessobjects
WHICH CONTAION the all classes which map the database Tables.


Now In My Fisrt Layer whic name is OnlineExam [It is website] and My Solution File name is OES.


The Mapping hb.xml Files in dbmappings Folderls which map Database tables one of then is
AnswerToMCQuestion.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8" ?>


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace=" OES.DAO.businessobjects" assembly="OES.DAO" >
    <class name="AnswerToMCQuestion" table="tAnswerToMCQuestion">
        <id name="Id">
            <column name="cId"/>
            <generator class="uuid.hex" />
        </id>
        <property name="CreationDateTicks">
            <column name="cCreationDateTicks"/>
        </property>
        <property name="IsRightAsInt">
            <column name="cIsRight"/>
        </property>
        <property name="AnswerText">
            <column name="cAnswerText"/>
        </property>
        <property name="NumInOrder">
            <column name="cNumInOrder"/>
        </property>
      <many-to-one
         name="Question"
         class="MultipleChoiceExamQuestion"
         column="cQuestionId"
         not-null="true"/>

    </class>
</hibernate-mapping>




Now The main Thing is Web.Config file setting where I got Error bz i dont know how to Map these .HBM.XML File here and how i give The Path bz My Business logic table which map the database tables in OES.DAO layesr .


Code:

<?xml version="1.0"?>
<configuration>
   <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
         <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <section name="scriptResourceHandler"  type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
               <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
               <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
            </sectionGroup>
         </sectionGroup>
      </sectionGroup>
      <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
   </configSections>



    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"    >
      <session-factory >
         <!-- SECTION TO BE CHANGED DEPENDING ON DATABASE AND RUNTIME ENVIRONMENT -->
         <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
         <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
         <property name="connection.connection_string">Data Source=.;Initial Catalog=sd;User ID=sa;Password=sa;</property>
         <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
         <property name="show_sql">false</property>

      [b]
      <mapping resource="../config/common/dbmappings/User.hbm.xml"    assembly="OES" />
      <mapping resource="../config/common/dbmappings/QuestionComment.hbm.xml"  assembly="OES"/>
      <mapping resource="../config/common/dbmappings/QuestionRating.hbm.xml"  assembly="OES" />
      <mapping resource="../config/common/dbmappings/TestExamination.hbm.xml" assembly="OES" />
      <mapping resource="../config/common/dbmappings/Exam.hbm.xml" assembly="OES"  />
      <mapping resource="../config/common/dbmappings/ExamSection.hbm.xml" assembly="OES" />
      <mapping resource="../config/common/dbmappings/Vote.hbm.xml" assembly="OES" />
         <mapping resource="../config/common/dbmappings/VoteByLink.hbm.xml" assembly="OES" />
      <mapping resource="../config/common/dbmappings/ExamQuestion.hbm.xml" assembly="OES" />
         <mapping resource="../config/common/dbmappings/AnswerToMCQuestion.hbm.xml" assembly="OES" />[/b]

    </session-factory>

  </hibernate-configuration>




  <system.web>
      <!--<trust level="Medium"/>-->
      <httpRuntime executionTimeout="1000" maxRequestLength="250000"/>
      <!--<sessionState mode="InProc" cookieless="false" timeout="180"/>-->
      <httpHandlers>
         <remove verb="*" path="*.asmx"/>
         <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
         <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
         <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
      </httpHandlers>
      <httpModules>
         <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </httpModules>
      <globalization culture="en-us" uiCulture="en"/>
      <compilation debug="true">
         <assemblies>
       
            <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
            <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
      </compilation>
      <!--<authentication mode="Forms">
         <forms loginUrl="Login.aspx"/>
      </authentication>-->
      <authorization>
         <allow users="*"/>
      </authorization>
      <customErrors mode="Off">
      </customErrors>
      <pages>
         <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
         </controls>
      </pages>
   </system.web>
   <!--<system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
         <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </modules>
      <handlers>
         <remove name="WebServiceHandlerFactory-Integrated"/>
         <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
         <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
         <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </handlers>
   </system.webServer>-->
</configuration>




In Mapping Tag i dont understand How I give The Path .
which Assempbly path I give .How I give the .HBM.XML File Path .

Please Help me All professionls .I am New In Nhibernate
I wam waiting For Replies.

Rakesh Gaur
mkclrakesh@gmail.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.