HHH-11209 involves a bug merging a detached entity with an uninitialized collection that has queued operations.
After looking into this issue I found a bug where AbstractPersistentCollection#operationQueue was not being cleared after a commit, if there was no cascade mapped for the collection. I've fixed that in a PR. [1] After that fix, the detached entity in the test case attached to HHH-11209 has an uninitialized entity without any queued operations after commit, which can be merged successfully in a new session/transaction. There is still a problem when Hibernate tries to merge a detached entity has an uninitialized collection with queued operations though. My PR throws UnsupportedOperationException in this case, and there is a test case that reproduces it. I've been working on a fix to add support for this, but I have my doubts that it really should be supported. I see that prior to fixing HHH-5855 (which caused HHH-11209), Hibernate simply ignored the queued operations in the detached collection. [2]. The fix for HHH-5855 properly dealt with merging a managed collection that was uninitialized with queued operations. It introduced the bug where a NullPointerException would get thrown if that collection was detached. If we want to support merging the queued operations, then I would consider that an improvement. Would this be a worthwhile improvement? I'm guessing not, but I wanted to get some opinions. For now, I see a couple of ways to deal with this so that HHH-11209 can be wrapped up: 1) ignore queued operations in a detached collection when merging, as was done before HHH-5855 was fixed. 2) clear the queued operations when the collection is detached. Comments? Thanks, Gail [1] https://github.com/hibernate/hibernate-orm/pull/2460 [2] https://github.com/hibernate/hibernate-orm/commit/c1934b72edb4f781520937618b3b750bebb84576#diff-2c7912a47063b9ea81323bf9c6628895L651 _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev