I'm on Hibernate 2.1 (we'll upgrade to 3.x on the next major product go-round).
I have a persisted object a one-many SortedSet relationship. I've done this before and it's not a problem. I just have the items in the sorted set implement Comparable.
I'm in a bit of quandry now though because the owning items determines the sort ordering. Bascially it looks like this:
class Foo
{
int sortOrder = {BY_DATE | BY_PRIORITY}
SortedSet<Bars> _bars = new TreeSet();
public void setBars( SortedSet bars ) { _bars = bars; }
}
The problem is the sorting of Bars depends on the instance of Foo. Some Foo objects want the Bars sorted by date, others by priority. Hibernate sets the SortedSet via setBars(). Defining a custom Comparator doesn't seem to help because I need to know Foo's sortOrder before I know which Comparator to use.
I can't even add logic in setBars() to resort the set, because I have no guarantee Hibernate calls setSortOrder( int order ) before it calls setBars().
Any suggestions? Right now I'm having to create a new TreeSet after the object is loaded and add all the _bars into it, then replace _bars with this new set. This ends up replacing Hibernates SortedSet though which I'm afraid might muck with lazy loading/proxies to the Bars array.
Thanks,
Chris
|