title: NHibernate multiple references to the same record from a single object
body: <p>I'm using Fluent NHibernate and the setup I have is as follows:</p>
  
  <p>An <strong>Address</strong> object, which is a simple list of address fields.</p>
  
  <p>A <strong>Company</strong> object which has two references to address objects, MainAddress, InvoiceAddress.</p>
  
  <p>The problem I'm having is that on occasion both MainAddress and InvoiceAddress may refer to the same record in the <strong>Address</strong> table.</p>
  
  <p><strong>Addresses</strong> are looked up by searching, using something along the lines of:</p>
  
  <pre><code>ICriteria c = session.CreateCriteria(typeof(Address))
              .Add(Example.Create(address).ExcludeNone());
  </code></pre>
  
  <p>Because each <strong>Address</strong> is selected seperately, this leads to two instances of the same record, which causes NHibernate to puke when trying to save the <strong>Company</strong> object.</p>
  
  <blockquote>
    <p>"a different object with the same identifier value was already associated with the session"</p>
  </blockquote>
  
  <p>What's the best way to work around this?</p>
  
  <p>Thanks!</p>