title: NHibernate: Cannot insert null exception when storing a new object
body: <p>I'm trying a very basic example with NHibernate but get an exception on session.Save() call.
  Here is my model:</p>
  
  <pre><code>public class Student
      {
          public virtual int ID { get; set; }
  
          public virtual string LastName { get; set; }
  
          public virtual string FirstMidName { get; set; }
      }
  </code></pre>
  
  <p>Here is Student.hbm.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; 
  
  &lt;hibernate-mapping xmlns = "urn:nhibernate-mapping-2.2" assembly = "NHibernateDemoApp" namespace = "NHibernateDemoApp"&gt;
  
      &lt;class name = "Student"&gt; 
          &lt;id name = "ID"&gt;
              &lt;generator class = "native"/&gt; 
          &lt;/id&gt; 
  
          &lt;property name = "LastName"/&gt; 
          &lt;property name = "FirstMidName"/&gt; 
      &lt;/class&gt; 
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>This the code to save an entity:</p>
  
  <pre><code>using (ISession session = this.sessionFactory.OpenSession())
              {
                  using (ITransaction transaction = session.BeginTransaction())
                  {
                      savedEntity = (Student) session.Save(new Student { ID = 1, FirstMidName = "Test first name", LastName = "Test Last name"});
  
                      try
                      {
                          transaction.Commit();
                      }
                      catch (Exception e)
                      {
                          Console.WriteLine(e);
                      }
                      finally
                      {
                          if (!transaction.WasCommitted)
                          {
                              transaction.Rollback();
                          }
                      }
                  }
              }
  </code></pre>
  
  <p>It fails with the following error:</p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'ID', table
    'NHibernateDemoDB.dbo.Student'; column does not allow nulls. INSERT
    fails.</p>
  </blockquote>
  
  <p>What's wrong here?</p>