title: Fluent NHibernate Objectified/Associated Relationship Mapping
body: <p>Ok I'm pretty new to Fluent and NHibernate and I'm not sure how to map this specific relationship that exists in my database. I have the following ER diagram below that outlines my table structure.</p>
  
  <p><img src="https://dl.dropbox.com/u/11595074/GroupRightDiagram.PNG" alt="ER Diagram"></p>
  
  <p>Below are my current C# entity classes and Fluent mappings:</p>
  
  <pre><code>public class GroupHeader
  {
      public virtual Guid Id { get; private set;}
      public virtual string Name { get; set; }
      public virtual string Description { get; set; }
      public virtual IList&lt;RightHeader&gt; AllowedRights { get; set; }
      public virtual IList&lt;RightHeader&gt; DeniedRights { get; set; }
      public virtual IList&lt;RightHeader&gt; UnsetRights { get; set; }
  }
  
  public class RightHeader
  {
      public virtual decimal Num { get; private set; }
      public virtual string Name { get; set; }
      public virtual string Description { get; set; }
  }
  
  public class GroupHeaderMap : ClassMap&lt;GroupHeader&gt;
  {
      public GroupHeaderMap()
      {
          Table("GROUP_HEADER");
          Id(x =&gt; x.Id, "GROUP_ID");
          Map(x =&gt; x.Name, "GROUP_NAME").Unique();
          Map(x =&gt; x.Description, "GROUP_DESCRIPTION");
  
          HasManyToMany(x =&gt; x.AllowedRights)
              .Table("GROUP_RIGHT_COMPOSITE")
              .ParentKeyColumn("GROUP_ID")
              .ChildKeyColumn("RIGHT_NUM")
              .Where("RIGHT_VALUE = 1")
              .Cascade.SaveUpdate();
  
          HasManyToMany(x =&gt; x.DeniedRights)
              .Table("GROUP_RIGHT_COMPOSITE")
              .ParentKeyColumn("GROUP_ID")
              .ChildKeyColumn("RIGHT_NUM")
              .Where("RIGHT_VALUE = -1")
              .Cascade.SaveUpdate();
  
          HasManyToMany(x =&gt; x.UnsetRights)
              .Table("GROUP_RIGHT_COMPOSITE")
              .ParentKeyColumn("GROUP_ID")
              .ChildKeyColumn("RIGHT_NUM")
              .Where("RIGHT_VALUE = 0")
              .Cascade.SaveUpdate();
      }
  }
  
  public class RightHeaderMap : ClassMap&lt;RightHeader&gt;
  {
      public RightHeaderMap()
      {
          Table("RIGHT_HEADER");
          Id(x =&gt; x.Num, "RIGHT_NUM");
          Map(x =&gt; x.Name, "RIGHT_NAME");
          Map(x =&gt; x.Description, "RIGHT_DESCRIPTION");
      }
  }
  </code></pre>
  
  <p>Currently whenever I create a new GroupHeader and populate the AllowedRights member variable it fails to insert these records because the RIGHT_VALUE column in GROUP_RIGHT_COMPOSITE doesn't allow nulls.  I'm not really sure how to map this in fluent or where I should really handle this in my entities.  Any help would be appreciated.</p>