[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7045) Entity as Map Key and hashCode

Robert Hollencamp (JIRA) noreply at atlassian.com
Thu Feb 9 10:12:10 EST 2012


Entity as Map Key and hashCode
------------------------------

                 Key: HHH-7045
                 URL: https://hibernate.onjira.com/browse/HHH-7045
             Project: Hibernate ORM
          Issue Type: Bug
          Components: entity-manager
    Affects Versions: 3.6.10, 4.0.1
         Environment: Tested 4.0.X, 3.6.X; tested PostgreSQL and Hypersonic
            Reporter: Robert Hollencamp
         Attachments: jpa-map-work.zip

I have an entity that has a unique field; this is used as the business key. The equals and hashCode methods of the entity class use this field.

When this entity is used as the key for a map, this unique field is not loaded when the map entry is inserted; this causes hashCode to return 0 ("return field != null ? field.hashCode() : 0;") and equals to return true, so no matter how many entries there are only one will be inserted.

If I prime the cache first by loading all of these key entities, it will then work. The attached test case demonstrates this.

--
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