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