[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-2634) PersistentSet.contains() and remove() do not work as expected
Emmanuel Bernard (JIRA)
noreply at atlassian.com
Thu May 24 10:47:04 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2634?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Emmanuel Bernard resolved HHH-2634.
-----------------------------------
Resolution: Rejected
Read Object.equals() and Object.hashCode() JavaDoc, alternatively, check the hibernate wiki area on the subject
> PersistentSet.contains() and remove() do not work as expected
> -------------------------------------------------------------
>
> Key: HHH-2634
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2634
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.1
> Environment: 3.2.1
> Reporter: Albert Zheng
>
> Scenario is as following:
> class P {
> private Set<C> children;
> ...
> }
> class C {
> private long id;
> public int hashCode() {
> return id;
> }
> }
> class C's id is generated with id generator and C.hashCode() method uses its id for calculation.
> Session session = sf.openSession();
> P p = session.load(P.class, id);
> C c = new C();
> p.getChildren().add(c);
> session.saveOrUpdate(p); //cascade is all, so c will be inserted into db
> System.out.println(p.getChildren().contains(c)); //this method will return false
> p.getChildren() is a PersistentSet, it has an internal HashSet to contain the object. When p.getChildren().add(c) is called, the HashSet put c into hash bucket with hashCode 0. After c is inserted into db, hibernate assigns a generated id for c, p.getChildren().contains(c) uses another hashCode to find c in the HashSet. Of course, this search will fail.
> I think Hibernate should re-construct the HashSet after persistenting a dirty PersistentSet.
> Also refer http://forum.hibernate.org/viewtopic.php?t=965543 for the issue discussion.
--
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