[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3007) Unchanged persistent set gets marked dirty on session.merge()

Lars Koedderitzsch (JIRA) noreply at atlassian.com
Tue Dec 11 09:13:57 EST 2007


Unchanged persistent set gets marked dirty on session.merge()
-------------------------------------------------------------

                 Key: HHH-3007
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3007
             Project: Hibernate3
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.5
            Reporter: Lars Koedderitzsch


Persistent sets are marked dirty on session.merge() even if there have been no changes to the collection.
This is especially painful when the collection is immutable and results in an "changed an immutable collection instance" exception on flush.

I tracked the behaviour down a bit and believe the problem to be in CollectionType.replace().

Here the passed in orginal PersistentSet is replaced by a plain HashSet in this line: 
Object result = target == null || target == original ? instantiateResult( original ) : target;

The "result" object (HashSet) is then passed to the CollectionType.replaceElements() method (instead of the original PersistentSet).
In CollectionType.replaceElements() the code to clear the dirty state of the collection does not execute anymore, because the passed-in "original" collection is the described HashSet and *not* the original PersistentSet.
This way the PersistentSet remains marked dirty.

A workaround is to manually clear the dirty state of an immutable collection after merge but before flush.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list