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

Nate Clark (JIRA) noreply at atlassian.com
Fri Feb 24 10:00:51 EST 2012


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

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

Yeah, I thought you might have that problem with my suggested approach. I'm not saying it isn't a tough problem, once you go with an approach that allows for dual IDs, and I'm not trying to insist that there's nothing the Hibernate folks could improve in this area. But we should also be clear that the problem is not that PersistentSet "violates the contract of how hashCode() is expected to behave". In fact, you could say this problem is partly caused by PersistentSet following the hashCode() contract (not to say the right solution is to break the contract, either). I maintain that the core hashCode/hashtable behavior we're seeing can be reproduced with a vanilla HashSet. (And iirc, PersistentSet actually uses a HashSet internally to perform these lookups.) The real violation of the hashCode contract is in maintaining two IDs and hashing on one or the other depending on context. As I said above, you are in essence changing the identity of the object after the fact, something that hashtable implementations don't play nice with. The problem stems from combining this aspect of the hashCode contract with the usual Hibernate/database management of IDs, in which entities are endowed with IDs only when they are saved. These two ideas, while they are both valuable and useful, are not 100% compatible.

> 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