I feel like I'm sooo close and just doing something dumb.
I've got an Activity that contains a list of Contributions. The Contributions point back to a single activity as their parent. I'm trying to let Hibernate maintain the indexes for me. When I add a list of contributions for the very first time, it works correctly, with the indexes on the contributions being what I expect.
contrib1[0], contrib2[1], contrib3[2]
However, if I try to add a new contribution to the list at the beginning, only the contribution I'm adding gets updated. The others don't get reindexed.
It becomes
contrib4[0], contrib1[0], contrib2[1], contrib3[2].
I've tried to "copy all elements, clear() the original instance, and addAll()" to no avail. From this article:
http://forum.hibernate.org/viewtopic.php?t=945944
I've gotta be close, does anyone see anything I might be missing?
Here's my list of Contribs in my Activity.hbm.xml
Code:
<list name="contribs"
lazy="true"
cascade="all-delete-orphan">
<key column="activityID"
not-null="true"
update="false"/>
<list-index column="pos" base="0"/>
<one-to-many class="Contrib"/>
</list>
Here's my activity from the contribution.
Code:
<many-to-one name="activity" class="Activity" column="activityID" not-null="true" insert="false" update="false" />
Here's where I add a new Contribution:
Code:
public void addContrib(Contrib inContrib, int pos)
{
inContrib.setActivity(this);
ArrayList newArray = new ArrayList(contribs);
newArray.add(pos,inContrib);
contribs.clear();
contribs.addAll(newArray);
}
Thanks for any help.