# HibenateException Found shared references to a collection

**URL:** <https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613>\
**Category:** Hibernate ORM\
**Created:** [November 14, 2024, 11:47am UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613 "2024-11-14T11:47:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrinivasva](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@shrinivasva](https://discourse.hibernate.org/u/shrinivasva)\
**Post date:** [November 14, 2024, 11:47am UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613/1 "2024-11-14T11:47:41Z")

</div>

Hi @all,

After Migration hibernate 5 to hibernate 6, as below I have Mapping :

```auto
@Entity
@Indexed
public class Case extends VersioningEntity {

@IndexedEmbedded(includePaths = {"allocatedTo", "outcome", "taskStatusType.id", "taskTypeId", "completedDate", "taskTypeOutcomeCombo","taskAdminCorrectionCode"})
	@OneToMany(mappedBy = "theCase", cascade = CascadeType.ALL, orphanRemoval = true)
	@JsonIgnore
	@XmlTransient
	private List<HistoryTask> historyTasks;

```

Similar in another entity as below :

```auto
public class HistoryTask implements Serializable {

@ManyToOne
	@JoinColumn(name = "case_id", nullable = false, insertable = false, updatable = false)
	@XmlTransient
	@JsonIgnore
	@BeanFieldIgnore
	private Case theCase;

@OneToMany
	@JoinColumn(name="`key`", referencedColumnName="task_outcome", insertable=false, updatable=false)
	@JsonIgnore
    @XmlTransient
	private Set<Translation> translations;	

```

But after save call , which linked to Case entity, I am getting below Error :

```auto
ERROR|2024-11-14 17:15:40,929|http-nio-8080-exec-11| CaseServiceImpl - CaseServiceImpl.saveCaseBasicInformation() EXCEPTION 
org.springframework.orm.jpa.JpaSystemException: Found shared references to a collection: com.eurodyn.eips.core.db.entity.HistoryTask.translations

```

Same code was working earlier with Hibenrate 5 / Hibernate search 5

Please suggest , what I am doing wrong here.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [November 14, 2024, 4:37pm UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613/2 "2024-11-14T16:37:12Z")

</div>

Hello @shrinivasva, the error is pretty self explanatory: Hibernate found multiple references that pointed to the same persistent collection instance. That’s usually caused by a bug, but since you’re using Spring and not providing a full stack trace of the error it’s pretty much impossible for us to understand what’s going on.

Please, try to create a simple project which uses only Hibernate that reproduces the error you’re encountering and share it so we might take a look, you can start from our [test case templates](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java).

---

<div class="post-metadata">

**Author:** ![shrinivasva](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@shrinivasva](https://discourse.hibernate.org/u/shrinivasva)\
**Post date:** [November 23, 2024, 10:42am UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613/4 "2024-11-23T10:42:45Z")

</div>

I fixed by changing mapping of translation to @ManyToOne in historyTask .

But I didn’t get how it was working in hibernate 5.x

---

<div class="post-metadata">

**Author:** ![shrinivasva](https://avatars.discourse-cdn.com/v4/letter/s/a87d85/32.png) [@shrinivasva](https://discourse.hibernate.org/u/shrinivasva)\
**Post date:** [November 25, 2024, 11:28am UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613/5 "2024-11-25T11:28:22Z")

</div>

You can find here test case :  
which you can try by updating versions [Jira](https://hibernate.atlassian.net/browse/HHH-16665)

I am using 6.6.3 hibernate

---

<div class="post-metadata">

**Author:** ![ArpitTodi](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@ArpitTodi](https://discourse.hibernate.org/u/ArpitTodi)\
**Post date:** [April 21, 2025, 4:21pm UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613/6 "2025-04-21T16:21:28Z")

</div>

Did we get solution for this in 6.6.3?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 29, 2025, 2:28pm UTC](https://discourse.hibernate.org/t/hibenateexception-found-shared-references-to-a-collection/10613/7 "2025-04-29T14:28:19Z")

</div>

@ArpitTodi the existing issue has apparently been fixed since `6.2.3`. If you’re experiencing similar problems, or believe there has been a regression, please open a new Jira issue that includes a simple reproducer test case.
