title: Hibernate Found shared references to a collection
body: <p>EDIT - I have simplified this post to reproduce the problem with a single set</p>
  
  <p>I have upgraded hibernate from 4.3.11 to 5.2.8 and am now getting a shared reference exception. Various related posts I have read dont seem to help.</p>
  
  <p>My db tables are
  <a href="https://i.stack.imgur.com/OAlRg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OAlRg.jpg" alt="enter image description here"></a></p>
  
  <p>These tables are used to represent "things" and "Things owned by things". e.g. Person owns house/s, houses own computer/s, computers own components. Etc All recursive sets of 'Master' to their 'Asset'. This worked perfectly prior to hibernate v5. </p>
  
  <p>MasterAsset.hbm.xml as follows</p>
  
  <pre><code>...
  &lt;many-to-one name="master" class="mypath.Master" fetch="select"&gt;
      &lt;column name="MASTER_ID" not-null="true" /&gt;
  &lt;/many-to-one&gt;
  
  &lt;many-to-one name="asset" class="mypath.Master" fetch="select"&gt;
      &lt;column name="MST_ASSET_ID" not-null="true" /&gt;
  &lt;/many-to-one&gt;
  ...
  
  &lt;set name="masterAssetLinkedToAsset" table="MASTER_ASSET" inverse="true" lazy="true" fetch="select"&gt;
      &lt;key column="MASTER_ID" property-ref="asset"/&gt;
      &lt;one-to-many class="mypath.MasterAsset"/&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>MasterAsset.java contains</p>
  
  <pre><code>  private Set&lt;MasterAsset&gt; masterAssetLinkedToAsset = new HashSet&lt;MasterAsset&gt;(0);
    private Master master;
    private Master asset;
  </code></pre>
  
  <p>All I do to get this problem is </p>
  
  <pre><code>creteria.list(MasterAsset)
  </code></pre>
  
  <p>which gives me this error :</p>
  
  <pre><code>javax.persistence.RollbackException: Error while committing the transaction
      at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:75)
      at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:71)
      at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:91)
      ... 
  Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Found shared references to a collection: mypath.domain.MasterAsset.masterAssetLinkedToAsset
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
      at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:56)
      ... 26 more
  Caused by: org.hibernate.HibernateException: Found shared references to a collection: mypath.domain.MasterAsset.masterAssetLinkedToAsset
      at org.hibernate.engine.internal.Collections.processReachableCollection(Collections.java:182)
      at org.hibernate.event.internal.FlushVisitor.processCollection(FlushVisitor.java:42)
      at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:104)
  </code></pre>