Hibernate version:3.1 rc1 (problem also occured in 3.0.5)
Hallo,
after searching through this and the german hibernate forum, I decided to post a question by myself.
I never saw a likewise problem, so I strongly suggest that I've done anything wrong. But I also can't find the point of failure.
Description: A Person(one) has Addresses(many) [in hibernate bidirectionally linked]; if a Person entity is deleted, all regarding adresses will be deleted too (cascade)...so long so good
The thing I want to do is to simply delete an address-entity of a person.
Because of cascading I just don't have to delete the address-entity, but also need to delete the regarding address-objekt from the address-list of person. And that's exactly the problem.
Code:
Adr adr;
boolean b;
...
b = adr.getPerson().getAdrSet().remove(adr);
// b:false
means, adr won't be delete from the Set (confirmed by .size() ), although
Code:
Iterator it =adr.getPerson().getAdrSet().iterator();
while (it.hasNext()) {
Adr adr2 = (Adr) it.next();
if (adr2.equals(adr)) {
b=true;
//it.remove(); even this doesn't work
break;
}
}//while
//b:true ...object was really found but not deleted
May be this has something to do with the implemented equals and hashCode methods?! There were generated by MyEclipse-HibernatePlugin:
(Example Adr)
Code:
public boolean equals(Object rhs)
{
if (rhs == null)
return false;
if (! (rhs instanceof Adr))
return false;
Adr that = (Adr) rhs;
if (this.getAdrId() == null || that.getAdrId() == null)
return false;
return (this.getAdrId().equals(that.getAdrId()));
}
public int hashCode()
{
if (this.hashValue == 0)
{
int result = 17;
int adrIdValue = this.getAdrId() == null ? 0 : this.getAdrId().hashCode();
result = result * 37 + adrIdValue;
this.hashValue = result;
}
return this.hashValue;
}
please help me blowing away the fog of nescience.
Thnx in advance
Btw: Hibernate is impressive