title: I'm sorry, but it's another: Found shared references to a collection
body: <p>Recently I've been adding some features to my local project, and I'm struggling with this one part. The short of it is NHibernate give me the line: </p>
  
  <pre><code>Found shared references to a collection: Page.Menus
  </code></pre>
  
  <p>The simple part of it is, I only want to save the relational map that binds menus to pages, which you can see the Reference below in <code>PageMap</code>. I should add that loading data works great, it's the saving that's killing me.</p>
  
  <p>I spent a lot of time yesterday digging through here, and the good ole web, trying to find the answer, and I just kept striking out. Maybe it's bad searching on my part, but I feel I tried everything. If you know where it is can you please supply it? (thanks)</p>
  
  <p>For the actual details, I've tried to simplify what's going on. I've added the PageReposity, UnitOfWork, and the proxy objects, as well as their mappings.</p>
  
  <p>Where I get hazy on is the cascade, and how to save the relationship table (many to many)</p>
  
  <p>For the first part, here is what happens when I save (Add). I've actually done this a few ways within the <code>PageRepository</code>. Since I'm strugging with the <code>Add()</code>, I've included it here:</p>
  
  <pre><code>public override bool Add(Page entity)
  {
      UnitOfWork.Save(entity);
  
      /* I have also tried doing the following below, which doesn't help 
      for (var index = 0; index &lt; entity.Menus.Count; index++)
      {
          UnitOfWork.Save(entity.Menus[index]);
      }
      */
  
      UnitOfWork.Commit(); // bam, error!
      return true;
  } 
  </code></pre>
  
  <p>In the <code>UnitOfWork</code> I've setup the following in the ctor (the ISession is injected each time via ninject like so:</p>
  
  <p>// <code>DomainModule</code>
      ...</p>
  
  <pre><code>Bind&lt;ISFactory&gt;().To&lt;NHibernateSessionFactory&gt;()
              .InSingletonScope()
              .WithConstructorArgument("connectionString", _connectWeb);
  ...
  </code></pre>
  
  <p>// Back to the <code>UnitOfWork</code></p>
  
  <pre><code>...
  
  private ISession Session { get; set; }
  
  ...
  
  public UnitOfWork(ISFactory sessionFactory)
  {
       _sessionFactory = sessionFactory.GetSessionFactory();
  
       Session = _sessionFactory.OpenSession();
       Session.FlushMode = FlushMode.Never; // I have also tried FlushMode.Commit
       _transaction = Session.BeginTransaction(IsolationLevel.ReadCommitted);
  } 
  
  ...
  
  public void Save(object obj)
  {
      Session.Save(obj);
  }
  
  ...
  
  public void Commit()
  {
      if (!_transaction.IsActive)
      {
          throw new InvalidOperationException("Oops! We don't have an active transaction");
      }
  
      try
      {
          _transaction.Commit();
          Session.Flush(); // I did this FlushMode.Never was set
      }
      catch (Exception exception)
      {
          _transaction.Rollback();
          throw;
      }
  }
  </code></pre>
  
  <p>I've got 3 classes here:</p>
  
  <p><code>Page</code>, <code>Menu</code>, and <code>Link</code>.</p>
  
  <pre><code>public class Page : IEntity&lt;int&gt;
  {
      public virtual int Id { get; set; }
  
      public virtual IList&lt;Menu&gt; Menus { get; set; }
  }
  
  public class Menu : IEntity&lt;int&gt;
  {
      public virtual int Id { get; set; }
  
      public virtual IList&lt;Link&gt; Links { get; set; }
  }
  
  public class Link : IEntity&lt;int&gt;
  {
      public virtual int Id { get; set; }
  
      public virtual DateTime CreatedDate { get; set; }
  
      public virtual string Url { get; set; }
  }
  </code></pre>
  
  <p>Then I also have a Mappings:</p>
  
  <pre><code>public class PageMap : ClassMap&lt;Page&gt;
  {
      public PageMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Native();
          HasManyToMany(x =&gt; x.Menus)
                          .Table("MenuToPage")
                          .ParentKeyColumn("FkPageId")
                          .ChildKeyColumn("FkMenuId").Cascade.SaveUpdate(); // the cascade is new here just trying to see if it helps
      }
  }
  
  public class MenuMap : ClassMap&lt;Menu&gt;
  {
      public MenuMap()
      {
          Id(x =&gt; x.Id); // I had .GeneratedBy.Native(); attached here too.
          HasManyToMany(x =&gt; x.Links)
              .Table("MenuToLinks")
              .ChildKeyColumn("FkLinksId")
              .ParentKeyColumn("FkMenuId")
              .OrderBy("MenuOrder ASC")
              .Not.LazyLoad()
              .Cascade.None(); // the cascade is new here just trying to see if it helps
      }
  }
  
  public class LinkMap : ClassMap&lt;Link&gt;
  {
      public LinkMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Native();
          Map(x =&gt; x.Url);
          Map(x =&gt; x.CreatedDate);
          Map(x =&gt; x.ModifiedDate);
          References(x =&gt; x.MetaData, "FkMetaDataId").Not.Nullable().Not.LazyLoad();
      }
  }
  </code></pre>
  
  <p>Can anyone help me or point me in a direction, I'd really appreciate your help. </p>
  
  <p>Like always thank you,</p>
  
  <p>Kelly</p>