title: NHibernate HasMany relation. Collection is null until session reopen
body: <p>I've got a problem with NHibernate and, as I suppose, with lazy load.</p>
  
  <p>I've got two entity classes, that are related to each other:</p>
  
  <pre><code>public class User
  {
      // lots of properties
      public virtual Role Role { get; set; }
  }
  
  public class Role
  {
      // properties
      public virtual IList&lt;User&gt; UsersInRole { get;set; }
      public Role()
      {
          this.UsersInRole = new List&lt;User&gt;();
      }
  }
  </code></pre>
  
  <p>Relation is One-To-Many (One role - Many users).
  Classes are mapped with Fluent as following:</p>
  
  <pre><code>public class UserMapping : ClassMap&lt;Models.Accounts.User&gt;
  {
      public UserMapping() 
      {
          this.Table("Users");
          this.Id(u =&gt; u.ID).GeneratedBy.Native();
          //properties mapping            
          this.References&lt;Models.Accounts.Role&gt;(u =&gt; u.Role);
      }
  }
  
  public class RoleMapping : ClassMap&lt;Models.Accounts.Role&gt;
  {
      public RoleMapping()
      {
          this.Table("Roles");
          this.Id(r =&gt; r.ID).GeneratedBy.Native();
          // properties mapping 
          this.HasMany&lt;User&gt;(r =&gt; r.Users).AsBag().Inverse().KeyColumn("Role_id");
      }
  }
  </code></pre>
  
  <p>When I'm creating a Role, and assign some User to it - Role::Users property is null until session is closed and another one is opened. So, consider following code:</p>
  
  <pre><code>object Foo()
  {
          var session = FluentManager.OpenNewSession();
          var t1 = session.BeginTransaction();
          Role role = new Role("admin");
          session.SaveOrUpdate(role);
          t1.Commit();
  
          var t2 = session.BeginTransaction();
          session.SaveOrUpdate(new User() { Login = "log1", Role = role });
          t2.Commit();            
  
          Role oldRole = session.Get&lt;Role&gt;((uint)1);
          return oldRole.Users; // null here
  }
  </code></pre>
  
  <p>On the other hand, following code works fine:</p>
  
  <pre><code>object Foo()
  {
          var session = FluentManager.OpenNewSession();
          var t1 = session.BeginTransaction();
          Role role = new Role("admin");
          session.SaveOrUpdate(role);
          t1.Commit();
  
          var t2 = session.BeginTransaction();
          session.SaveOrUpdate(new User() { Login = "log1", Role = role });
          t2.Commit();
          session.Close();
  
          var session2 = FluentManager.OpenNewSession();
          Role oldRole = session2.Get&lt;Role&gt;((uint)1);
          return oldRole.Users; // Actual list of users
  }
  </code></pre>
  
  <p>Though, I'd like to work with collection of users in a given role w/out session close. What I did wrong?
  Many thanks in advance.</p>
  
  <p>PS: I'm using Fluent NHibernate 1.2 with SQLite database, if that matters.</p>