If defining a bi-directional, one-to-many association that is supposed to be an "ORDERED" list, the proper code to allow Hibernate to manage the index is not generated.
Discussed in this post (
http://galaxy.andromda.org/forum/viewtopic.php?p=3909#3909 ), the relevant information:
Per the Hibernate FAQ at
http://www.hibernate.org/193.html ....
Assume I've set the namespace property associationEndCollectionIndexName to the value of "listPosition".
If using Hibernate 2, the following additional code would need to be generated in the child entity's Java classes IF doing a bi-directional, one-to-many, ordered association:
Code:
private int listPosition;
public int getListPosition()
{
return this.get<nameOfParentEntity>().get<nameOfThisEntityInParent>().indexOf(this);
}
private void setListPosition(int index)
{
// not used, calculated value, see getIndex() method
}
Also, the "listPosition" attribute would need to be added to the child entity's Hibernate HBM file.
For Hibernate 3, the following change would be needed:
in the parent entity's HBM file, where the <list> mapping is, the "inverse" attribute should be set to FALSE (it is currently set to "true").
in the child entity's HBM file, where the <many-to-one> mapping is, the attributes "update" and "insert" both need to be set to false.