HibenateException Found shared references to a collection

Hi @all,

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

@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 :

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 :

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.

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.

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

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