title: NHibernate.TypeMismatchException: Provided id of the wrong type. Expected: System.Int32, got System.Int64
body: <p>Am using the following query to get a Client. The Client has a public Id of type long. </p>
  
  <pre><code>var client = Session.CreateQuery("from Client as c where c.Id = :Id").SetParameter("Id", 1, NHibernateUtil.Int64).UniqueResult&lt;Client&gt;();
  </code></pre>
  
  <p>Am getting the error: </p>
  
  <blockquote>
    <p>NHibernate.TypeMismatchException: Provided id of the wrong type. Expected: System.Int32, got System.Int64</p>
  </blockquote>
  
  <p>At the same time, the following works just fine.</p>
  
  <pre><code>var client = Session.Get&lt;Client&gt;(1L); //Or
  var client = Session.CreateCriteria&lt;Client&gt;().Add(Restrictions.Eq("Id", 1L)).UniqueResult&lt;Client&gt;();
  </code></pre>
  
  <p>What am i missing? Am using fluent nhibernate to create the mappings. I have tested the queries against a Sqlite and a MySql database. Same results.</p>
  
  <p><strong>Edit1</strong>: The schema generation from the mappings clearly is using bigint for the primary key on mysql. Thats why i am unable to understand what is expecting a Int32? </p>
  
  <p><strong>Edit2</strong>: okay, my Client class has a reference to a Report object. Its actually a one-to-one relationship in the db with the report table having a column clientID. The Report class had an id of type int. Once i changed its type to long, the error went away. </p>
  
  <p>My mappings are as follows:</p>
  
  <p>ClientMap: </p>
  
  <pre><code>HasOne&lt;Report&gt;(x =&gt; x.Report)
     .PropertyRef(x =&gt; x.Client)
     .LazyLoad()
     .Cascade.SaveUpdate();
  </code></pre>
  
  <p>ReportMap:</p>
  
  <pre><code>References(x =&gt; x.Client, "clientID").Unique();
  </code></pre>
  
  <p><strong>So, why did the problem solve itself by changing the type of the reportid from int to long. Secondly, why is it even bothering to fetch the report when i am not asking for it?</strong></p>