title: Found shared references to a collection: ManyToMany
body: <p>I have an entity which is joined to it's self in a ManyToMany fashion:</p>
  
  <p>I want to have search results which may have 'related' results nested.
  Related results shouldn't appear under more then one primary result, but they could.
  Related results won't have any related results, this only goes one level deep.</p>
  
  <pre><code>@Entity
  @Table(name = "SEARCH_RESULTS")
  public class Result {
      @Id
      private Long seq;
  
      @ManyToMany(fetch = FetchType.LAZY, targetEntity = Result.class)
      @JoinTable(name = "SEARCH_RESULTS", 
         inverseJoinColumns = {
             @JoinColumn(name = "SEQ", referencedColumnName = "SEQ", 
                   updatable = false, insertable = false) },
         joinColumns = { 
             @JoinColumn(name = "related_id", referencedColumnName = "related_id", 
                   updatable = false, insertable = false, nullable = true), })
      @FilterJoinTable(name="SEARCH_RESULTS",condition="IS_PRIMARY_RESULT IS FALSE")
      private List&lt;Result&gt; related;
  }
  </code></pre>
  
  <p>Now, I'm using Lazy loading and a ManyToMany relation and applying a Criteria of IS_PRIMARY_RESULT IS TRUE when fetching my entities.</p>
  
  <p>For simple nesting it's working fine, but Hibernate complains when the join'd 'related' collection is shared between multiple primary Results.</p>
  
  <p>The exception I'm getting is:</p>
  
  <pre><code> org.hibernate.HibernateException: Found shared references to a collection: abc.Results.related
  </code></pre>
  
  <p>Is there anyway to make hibernate allow the collection to be shared?
  I tried using a @OneToMany, but when the table has multiple primary results with the same group_id, it bombs with the same error.</p>
  
  <p>FYI: this is a temp table produced by a stored procedure.</p>