From 88882cd2d850fe63104008cb30135196304f2068 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 17 Jul 2024 14:13:57 +0200 Subject: [PATCH] HHH-18289 with leads to HibernateException: A collection with cascade= was no longer referenced by the owning entity instance --- .../src/main/java/org/hibernate/type/CollectionType.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java index ca6c82e4fa..b911118ee1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java @@ -654,7 +654,12 @@ public abstract class CollectionType extends AbstractType implements Association final Object owner, final Map copyCache) throws HibernateException { if ( original == null ) { - return null; + if ( target == null ) { + return target; + } + final Collection collection = (Collection) target; + collection.clear(); + return collection; } if ( !Hibernate.isInitialized( original ) ) { if ( ( (PersistentCollection) original ).hasQueuedOperations() ) {