-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SortedSet where the Comparator is instance dependent?
PostPosted: Wed Oct 12, 2005 4:18 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 3:19 pm
Posts: 34
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.