title: NHibernate Exception Occurred getter of Id; Object does not match target type
body: <p>I am struggling with mapping subclasses using NHibernate.  I am saving reports that we generate and currently there are <strong>two different criteria types</strong> that I am serializing and would like to store in one column (Criteria) per report: <strong>Basic</strong> and <strong>Time</strong>.  Every report will have an XML column for criteria that is not null.  Here are my classes:</p>
  
  <p>My <strong>Report</strong> class is the primary class being mapped:</p>
  
  <pre><code>namespace Core {
      public class Report {
          public virtual int ReportId { get; set; }
          public virtual string Name { get; set; }
          public virtual ReportCriteria Criteria { get; set; }
      }
  }
  </code></pre>
  
  <p>My <strong>ReportCriteria</strong> class is abstract and inherited by the two criteria types:</p>
  
  <pre><code>namespace Core{
      [XmlRoot("Criteria"), Serializable]
      public abstract class ReportCriteria {
          public abstract string GenSql();
      }
  }
  </code></pre>
  
  <p>My <strong>BasicCriteria</strong> class inherits from ReportCriteria and uses the GenSql() method:</p>
  
  <pre><code>namespace Core {
      [XmlRoot("Criteria"), Serializable]
      public class BasicCriteria : ReportCriteria {
          public override string GenSql(){
              //method implementation
          }
      }    
  }
  </code></pre>
  
  <p>My <strong>TimeCriteria</strong> class inherits from ReportCriteria and uses the GenSql() method:</p>
  
  <pre><code>namespace Core {
      [XmlRoot("Criteria"), Serializable]
      public class TimeCriteria : ReportCriteria {
          [Past]
          public virtual DateTime StartDate { get; set; }
          public virtual DateTime EndDate { get; set; }
          public override string GenSql(){
              //method implementation
          }
      }    
  }
  </code></pre>
  
  <p>Finally, my mapping file (<strong>Report.hbm.xml)</strong> is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping namespace="Core" assembly="Core" xmlns="urn:nhibernate-mapping-2.2"&gt;
      &lt;class name="Report" table="Report"&gt;
          &lt;id name="ReportId"&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;discriminator column="CriteriaType" /&gt;
          &lt;property name="Name" /&gt;
          &lt;subclass name="Core.BasicCriteria" discriminator-value="Basic"&gt;
              &lt;property name="Criteria" type="Data.NHibernate.XmlSerializableType`1[[Core.BasicCriteria, Core]], Data" /&gt;
          &lt;/subclass&gt;
          &lt;subclass name="Core.TimeCriteria" discriminator-value="Time"&gt;
              &lt;property name="Criteria" type="Data.NHibernate.XmlSerializableType`1[[Core.TimeCriteria, Core]], Data" /&gt;
          &lt;/subclass&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Data.NHibernate.XmlSerializableType is a class which accepts generic types and serializes them for data persistence.  </p>
  
  <p>Please help me figure out what is wrong with my mapping which is causing the following error to occur:
  Ex: <strong><em>Exception occurred getter of Core.Report.ReportId</em></strong> 
  Inner: <strong><em>Object does not match target type.</em></strong></p>
  
  <p>Thanks in advance!</p>