title: NHibernate.LazyInitializationException
body: <p>We have been having this issue pop up sporadically, but now I can reproduce it every time.  I am incrementing a view counter on my custom built forums, which causes an error:</p>
  
  <blockquote>
    <p>NHibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed</p>
  </blockquote>
  
  <p>This error occurs on another collection in the object.  If I add:</p>
  
  <p>.Not.LazyLoad()</p>
  
  <p>To my Fluent mapping, the error shifts around my project.  I kept disabling lazy loading on objects intil it going to a spot where there was no lazy loading, and then it threw this error:</p>
  
  <blockquote>
    <p>NHibernate.LazyInitializationException: Could not initialize proxy - no Session.</p>
  </blockquote>
  
  <p>So, then I took out the nots on my lazy loading and now I'm back to square one.  It only errors when I increment this view counter.  Here is a snippet of my base class save code:</p>
  
  <pre><code>using (ISession session = GetSession())
  using (ITransaction tx = session.BeginTransaction())
  {
         session.SaveOrUpdate(entity);
         tx.Commit();
  }
  </code></pre>
  
  <p>Looking around, I read in another post that the transactions can cause an issue, but that was because of where they were placed.  This code is extended to classes that are separate from my domain objects (repository classes).  Here is the post:</p>
  
  <p><a href="https://stackoverflow.com/questions/345705/hibernate-lazyinitializationexception-could-not-initialize-proxy">hibernate: LazyInitializationException: could not initialize proxy</a></p>
  
  <p>I don't believe that is my issue here.  Here is my fluent mapping for the first collection that is throwing the error.  There are several other similar collections.</p>
  
  <pre><code>HasManyToMany(x =&gt; x.Votes)
      .WithTableName("PostVotes")
      .WithParentKeyColumn("PostId")
      .WithChildKeyColumn("VoteId");
  </code></pre>