I've been following the documentation here:
http://www.hibernate.org/193.html
and have a question:
If I add objects that contain identical values to a List and persist them, they correctly appear in the database with an ID of 0 and 1, and an index_col of 0 and 1.
i.e.
Code:
ID Name ParentId Index_col
0 foo 0 0
1 foo 0 1
2 foo 1 0
3 foo 1 1
If I override the Equals method, to compare just for business equality, (i.e. not comparing the ID) then the following code fails:
public int getIndex()
{
return this.getParent().getChildren().indexOf(this);
}
as the first item in the List will always be returned.
For Bidirectional one-to-many relationships with an indexed collection should I NOT override the Equals method?