Skip to content

Commit 7d071f5

Browse files
dreab8beikov
authored andcommitted
HHH-13815 TransientObjectException after merging a bidirectional one-to-many with orphan deletion
1 parent f2a73c9 commit 7d071f5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,8 +1297,8 @@ protected static <E> Collection<E> getOrphans(
12971297
// iterate over the *old* list
12981298
for ( E old : oldElements ) {
12991299
if ( !currentSaving.contains( old ) ) {
1300-
final Object oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session );
1301-
if ( !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) {
1300+
final Object oldId = ForeignKeys.getEntityIdentifier( entityName, old, session );
1301+
if ( oldId != null && !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) {
13021302
res.add( old );
13031303
}
13041304
}

hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,21 @@ public static Object getEntityIdentifierIfNotUnsaved(
371371
}
372372
}
373373

374+
public static Object getEntityIdentifier(
375+
final String entityName,
376+
final Object object,
377+
final SharedSessionContractImplementor session) {
378+
if ( object == null ) {
379+
return null;
380+
}
381+
else {
382+
final Object id = session.getContextEntityIdentifier( object );
383+
return id == null
384+
? session.getEntityPersister( entityName, object ).getIdentifier( object, session )
385+
: id;
386+
}
387+
}
388+
374389
private static void throwIfTransient(String entityName, Object object, SharedSessionContractImplementor session) {
375390
if ( isTransient( entityName, object, Boolean.FALSE, session ) ) {
376391
throw new TransientObjectException(

0 commit comments

Comments
 (0)