Skip to content

Commit a920bf1

Browse files
committed
HHH-2862 Throw error instead of replacing collection with same key
1 parent 57b8637 commit a920bf1

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,13 +1090,9 @@ private void addCollection(PersistentCollection<?> coll, CollectionEntry entry,
10901090
if ( old == coll ) {
10911091
throw new AssertionFailure( "bug adding collection twice" );
10921092
}
1093-
// or should it actually throw an exception?
1094-
old.unsetSession( session );
1095-
if ( collectionEntries != null ) {
1096-
collectionEntries.remove( old );
1097-
}
1098-
// watch out for a case where old is still referenced
1099-
// somewhere in the object graph! (which is a user error)
1093+
throw new HibernateException(
1094+
"Found shared references to a collection: " + collectionKey.getRole()
1095+
);
11001096
}
11011097
}
11021098

0 commit comments

Comments
 (0)