[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3799) PersistentSet does not honor hashcode/equals contract when loaded eagerly

Nate Clark (JIRA) noreply at atlassian.com
Thu Feb 23 13:09:51 EST 2012


    [ https://hibernate.onjira.com/browse/HHH-3799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45658#comment-45658 ] 

Nate Clark commented on HHH-3799:
---------------------------------

Seems to me PersistentSet is behaving in a manner consistent with the (express or implied) contract established by Java. By definition, if the result of hashCode() changes, the identity of the object changes. If non-ID items are included in hashCode() that can be null at one moment and not-null at another, or can change values in any other way, then any hash table implementation relying on hashCode will fail, because things will henceforth be assigned to the wrong buckets. The only option for correcting it is to remove the object and re-add it.

Yes, eager loading shouldn't necessarily be subject to this problem, since Hibernate could in theory completely initialize the object before adding it to the PersistentSet, but I still think one is treading on very thin ice by including Hibernate-managed persistent, non-ID class members in the calculation of a hashCode at all, because the results would be unsatisfying even when you're lazily loading those members.  (1) Initializing a PersistentSet would automatically also initialize all the proxies in the set. (2) If the Hibernate ID of an object is sufficient to establish its identity/uniqueness, then the Hibernate ID should also suffice for hashCode calculation. If not, I think you have an object identity bug waiting to happen elsewhere.

> PersistentSet does not honor hashcode/equals contract when loaded eagerly
> -------------------------------------------------------------------------
>
>                 Key: HHH-3799
>                 URL: https://hibernate.onjira.com/browse/HHH-3799
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.1, 3.5.1
>            Reporter: Igor Vaynberg
>            Assignee: Gail Badner
>         Attachments: test.zip
>
>
> when persistent set is loaded eagerly in some situations it calls hashcode on its items before their field values are populated and then uses this incorrect hashcode to store them in the set. this makes set items inaccessible by any collection items that rely on hashcode such as contains(), remove(), etc.
> attached is a simple maven test project that reproduces the error, unzip and mvn test to run the test.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list