From fefadfe6ea093a3ed64849a66c27852c1b2af377 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 13 Dec 2024 17:55:15 +0100 Subject: [PATCH] HHH-13815 TransientObjectException after merging a bidirectional one-to-many with orphan deletion --- .../collection/spi/AbstractPersistentCollection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java index ff2dd2b7788..fa6bf298b4e 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java @@ -1295,8 +1295,8 @@ protected static Collection getOrphans( // iterate over the *old* list for ( E old : oldElements ) { if ( !currentSaving.contains( old ) ) { - final Object oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session ); - if ( !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) { + final Object oldId = ForeignKeys.getEntityIdentifier( entityName, old, session ); + if ( oldId != null && !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) { res.add( old ); } }