# False positive HibernateException: Found shared references to a collection with 6.2.2

**URL:** https://discourse.hibernate.org/t/false-positive-hibernateexception-found-shared-references-to-a-collection-with-6-2-2/7676
**Category:** Hibernate ORM
**Created:** [May 22, 2023, 11:58am UTC](https://discourse.hibernate.org/t/false-positive-hibernateexception-found-shared-references-to-a-collection-with-6-2-2/7676 "2023-05-22T11:58:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![amir](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/amir/32/2415_2.png) [@amir](https://discourse.hibernate.org/u/amir)
#### Post date: [May 22, 2023, 11:58am UTC](https://discourse.hibernate.org/t/false-positive-hibernateexception-found-shared-references-to-a-collection-with-6-2-2/7676/1 "2023-05-22T11:58:29Z")

</div>

Hi,  
Trying to update hibernate 6.2.2 and getting Found shared references to a collection  
It is a bit hard to explain exactly as system is quite old and big and hard exactly to find everything what it is doing during an action that causes the issue, but I think I was able to isolate issue in the PR.

So I have the following setup:  
Product → one-to-one-\>Sku-(embeds)-PriceListSkuImpl-\>one-to-many-\>SkuPriceData  
|  
one-to-many  
|  
CategoryProductXref-\>many-to-one-\>Category

At some point I’m “cloning” a product(given the error I checked a number of times that I don’t re-assign or “clone” any collection) which in test-case I mimic by creating a new product. Then do refresh to both original and clone and that’s it.  
In test I also read category, and some other product, and initialize collections by accessing them, which seems is required to reproduce the issue.  
So once the final flush is happening I’m getting the Found shared references error for SkuImpl.priceListSku.priceDataList  
And the interesting thing that error(if you do debug) will be related to some other product/sku that didn’t participate in the cloning process, but just belong to the same category that original product does.

While debigging I think there is some issue with handling cycles in the entity graph, so seems it does:  
Product-\>sku-\>priceDataList  
then it does  
Product-\>category\_xref-\>category-\>all-product-in-category-\>category\_xref-\>product-\>sku-\>priceDatalist  
and fails…

I fixed the issue in my project just removing cascade.REFRESH  
While I think it is required to review refresh cascades as they are defined on both sides or relationships(not sure why but this is very old code), I think this is not an error and no exception should be thrown.  
Please correct me if I’m wrong and mapping is incorrect.  
This setup was working for ages since I think hibernate 3…

here it is PR that demonstrates issue

> <https://github.com/hibernate/hibernate-test-case-templates/pull/271>
>
> demonstrates false positive org.hibernate.HibernateException: Found shared refer…ences to a collection

---

<div class="post-metadata">

### Author: ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)
#### Post date: [May 22, 2023, 12:39pm UTC](https://discourse.hibernate.org/t/false-positive-hibernateexception-found-shared-references-to-a-collection-with-6-2-2/7676/2 "2023-05-22T12:39:00Z")

</div>

Thanks a lot for working on a reproducer for this. Can you please create an issue in the issue tracker([https://hibernate.atlassian.net](https://hibernate.atlassian.net)) and attach that reproducer there?

---

<div class="post-metadata">

### Author: ![amir](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/amir/32/2415_2.png) [@amir](https://discourse.hibernate.org/u/amir)
#### Post date: [May 22, 2023, 12:57pm UTC](https://discourse.hibernate.org/t/false-positive-hibernateexception-found-shared-references-to-a-collection-with-6-2-2/7676/3 "2023-05-22T12:57:12Z")

</div>

thanks for your answer  
[https://hibernate.atlassian.net/browse/HHH-16665](https://hibernate.atlassian.net/browse/HHH-16665)

---

<div class="post-metadata">

### Author: ![bmel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/bmel/32/2889_2.png) [@bmel](https://discourse.hibernate.org/u/bmel)
#### Post date: [December 24, 2023, 8:36pm UTC](https://discourse.hibernate.org/t/false-positive-hibernateexception-found-shared-references-to-a-collection-with-6-2-2/7676/4 "2023-12-24T20:36:16Z")

</div>

I seem to have a similar issue, with Hibernate 6.3.1.Final.  
Works fine with 6.2.13.Final.
