-->
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: Associated Set multiple sort orders at run time
PostPosted: Tue Jan 18, 2011 1:51 pm 
Newbie

Joined: Thu Oct 07, 2004 3:53 pm
Posts: 10
How can I at runtime specify a sort order for an associated Set of entities?

Given the following Company class and a query like " from Company order by foundedDate ", I'd like to be able to sometimes iterate over employees in name order and other times in age order.

class Company {
Set employees = new HashSet();
}

I could use the @Sort annotation as @Sort(type = SortType.COMPARATOR, comparator = SomeComparator.class), but that will only let me have one order. As far as I know there's no way at runtime to specify a different comparator.

I could also use Collection orderedCollection = session.filter( collection, "order by this.amount" ), but that doesn't change the iteration order of company.getEmployees(). If I have a list of companies, I have to call session.filter for each company. I'd like a way at runtime to specify how I want employees ordered.

I tried @Filter(name = "someFilter", condition = " order by name asc ") and while you can put more than one @Filter on an entity association, you can't use "order by" in the condition (kind of strange because you can use "order by" with session.filter()).

So I am stuck. It seems like a simple thing and like it would be easy for Hibernate to implement. If anyone knows how to do this, I would be extatic.


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.