I am in the process of upgrading my application to Hibernate3 and things are going well with one exception. One of my sets is sorting in the wrong order.
Here is the relevant .hbm snippet:
Code:
<set
cascade="all-delete-orphan"
name="ChildInCampWeekSet"
table="ChildInCampWeek"
sort="camp.ChildInCampWeek$ChildInCampWeekComparator"
inverse="true"
>
<key column="ChildId" />
<one-to-many class="ChildInCampWeek" />
</set>
As you can see, there is a comparator to do the sorting. However, I notice that this comparator is not being called. For example, I have some test code:
Code:
Child child = DBLayer.loadChild(childId);
Set<ChildInCampWeek> childInCampWeekSet = child.getChildInCampWeekSet();
for (ChildInCampWeek ciCW : childInCampWeekSet) {
System.out.println("Start date is: " + ciCW.getCampWeek().getWeek().getStartDate().toString());
}
The output shows that the start dates are sorted from last to first, not first to last. My initial thought was that somehow my comparator worked fine on Hibernate 2.1, but somehow there was a subtle bug that caused my comparator to fail in Hibernate 3. But instrumenting the comparator seems to indicate that it is not even being called.
I have tried modifying the Set above to be a SortedSet, but no change (and that required me to modify the code that HibernateSynchonizer generated).
I have also looked at the generated SQL and I do not see any order by clauses being generated.
Any ideas as to what I may have stumbled into are greatly appreciated!
Thanks SO much!
RB