Two revealing posts from the Hibernate forum:
http://www.hibernate.org/193.html
and
(if you are using Hibernate 3):
http://forum.hibernate.org/viewtopic.ph ... =listindex
Also, I believe there is a bug in this "ordered list" feature of the AndroMDA Hibernate Cartridge. Some additional code needs to be generated. Per the FAQ reference above (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: Select all
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.
If I can figure out how to make a patch, I may submit the fix. Otherwise, can the person who works on the Hibernate cartridge make this fix?
