title: NHibernate Object reference not set to an instance of an object
body: <p>This is my first time using NHibernate and i am trying to create an application using MVC 4, here is my configuration file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" &gt;
    &lt;session-factory &gt;
      &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
      &lt;property name="connection.driver_class"&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
      &lt;property name="connection.connection_string"&gt;Data Source=.\SQLEXPRESS;Initial Catalog=loc;Persist Security Info=True;Trusted_Connection=Yes;Pooling=yes;connection lifetime=300;User Id=sa;Password=###&lt;/property&gt;
      &lt;property name="dialect"&gt;NHibernate.Dialect.MsSql2008Dialect&lt;/property&gt;
      &lt;property name="show_sql"&gt;false&lt;/property&gt;
  </code></pre>
  
  <p>and the mapping file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                     assembly="HelloWorldHib"
                     namespace="HelloWorldHib.Mappings"&gt;
    &lt;class name="Product" table="Products"&gt;
      &lt;id name="Id" column="Id"&gt;
        &lt;generator class="native"&gt;&lt;/generator&gt;
      &lt;/id&gt;
      &lt;property name="Name"&gt;&lt;/property&gt;
      &lt;property name="Category"&gt;&lt;/property&gt;
      &lt;property name="IsDis"&gt;&lt;/property&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>
   
  </p>
  
  <p>And the helper:</p>
  
  <pre><code>public class NHibernateHelper
  {
      private static ISessionFactory _sessionFactory;
      private static Configuration cfg;
  
      private static ISessionFactory SessionFactory
      {
          get
          {
              if (_sessionFactory == null)
              {
                  cfg.Configure(HttpContext.Current.Server.MapPath("~/hibernate.cfg.xml"));
                  cfg.AddDirectory(new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath(@"~/Mappings")));
                  cfg.AddAssembly(typeof(Product).Assembly);
                  _sessionFactory = cfg.BuildSessionFactory();
  
                  if (_sessionFactory == null)
                      throw new InvalidOperationException("session factory could not be built");
              }
              return _sessionFactory;
          }
      }
  
      public static ISession OpenSession()
      {
          ISession session;
  
          session = _sessionFactory.OpenSession();
          if (session == null)
              throw new InvalidOperationException("session could not be opend");
  
          return session;
      }
  }
  </code></pre>
  
  <p>When i run my app i get <code>Object reference not set to an instance of an object</code> on this line <code>session = _sessionFactory.OpenSession()</code></p>
  
  <p>The table exist in the database, what is the problem?</p>
  
  <p>Thanks</p>