No need to clear an unmodified managed persistent collection in preparation for merge

Description

Fails with:

Full test case available at [1].

Problem is visible also when using spring-data [2].

[1] https://github.com/hibernate/hibernate-orm/compare/master...bostko:test-merge-immutable
[2] https://github.com/bostko/test-spring-data

Activity

Show:

Steve Ebersole April 6, 2019 at 4:49 PM

FWIW, I also do not think the orphan removal was any bearing in this test case. At least if I understand the use case correctly. It's not that the collection is generally immutable, he just happens to be using an immutable version in this use case. And here that should be fine.

Generally speaking you are correct. Just talking about this specific example

Steve Ebersole April 6, 2019 at 4:45 PM

Yep, that's what I am suggesting.

On Fri, Apr 5, 2019, 4:49 PM Gail Badner (JIRA) <

Former user April 5, 2019 at 9:49 PM

, I've looked a little more. I think that it makes sense for CollectionType#replace to simply return the original collection when the collection is managed and not dirty.

Former user April 5, 2019 at 7:18 PM

Related to the test – orphanRemoval = true for a collection mapped as @Immutable is invalid, since an immutable collection should not have entities removed from it. The only exception is if the collection owner is deleted. I that case, cascade=DELETE should be used instead.

Steve Ebersole April 5, 2019 at 11:09 AM

The issue here is not so much the use of the immutable list.

The "issue" is that we really do not need to clear the bag (collection) as part of the merge handling for this particular case. Specifically - when we are merging an unmodified managed collection, there is no need to perform the clear first. Unless I miss some case. , you seemed to have some thoughts on case(s) where this would not hold true - could you list them here? Based on that, maybe this is (1) something even less generally applicable or (2) something we simply want to not do.

Either way, outside of this stipulation.. merging a non-`@Immutable` immutable collection is not really a valid use case. FWIW, in the example you gave , the merge is actually completely pointless. Everything between the persist and commit would have no ultimate effect here.

Details

Assignee

Reporter

Components

Fix versions

Priority

Created April 1, 2019 at 3:04 PM
Updated June 24, 2022 at 2:06 PM