I still can't seem to get the list-index to be updated. I have changed my approach to try and implement something like this
http://www.hibernate.org/193.html even though from what I have read I should be able to do indexed collections in a bidirectional association with Hibernate 3. Using this Hibernate 2 approach my new mapping like this:
<list name="children" table="CATEGORIES" lazy="false" inverse="false" >
<key column="PARENT_ID" />
<list-index column="CHILD_ORDER" base="0" />
<one-to-many class="software.executiveutilities.model.Category" />
</list>
<many-to-one name="parent" column="PARENT_ID" class="software.executiveutilities.model.Category" />
<property name="childOrder" column="CHILD_ORDER" type="int" update="true" insert="true"/>
Now according to the documentation, this should work :
private int getChildOrder()
{
return this.getParent().getChildren().indexOf(this);
}
private void setChildOrder(int index)
{
// not used, calculated value, see getIndex() method
}
I can understand how this would work for retrieving the childOrder from a given Category, but how does this work for setting the order? When I add a new child Category to the list, the childOrder of children is still not being updated. Do I have to do these updates to Category.childOrder manually? For example, add a new Category to the list of children, then go through each of the children and set their childOrder approriately? Surely, there is a better way? This seems WAY to difficult to maintain. Any help is MUCH appreicated.