Cool stuff, Jon. I have another couple of suggestions as well:
1. If using HQL, you can avoid the manual join by using "member of", like so:
"select b from Beer b, User u where
u.id = :UserId and b member of u.myFavorites order by b.beerStyle desc"
2. You could use a collection
filter. These are not supported via CF integration, but you can create
them yourself using the Hibernate session (similar to what Jon did with the Criteria object). Here's an example that I
think will give you what you want:
User = entityLoadByPK("User",1);
filter = ormGetSession().createFilter(User.getmyFavorites(),"order by this.beerStyle desc").setFirstResult(0).setMaxResults(20);
beersArray = filter.list();
One issue with this is that you need to have a persistent User object first (hence the first line call to entityLoadByPK). The criteria approach might work better if you just want to run a query, without having a User object already, and it also allows you to isolate your order by criteria a bit more. These filters are very cool, though, as they basically allow you to run queries against your collection properties, so, for example, you could paginate a collection, or change sort sequence, or subselect.
I'm going to write a post about them with a bit more detail, when I can find the time. ;-)
Oh, one more thing. You misspelled favourite. ;-)
Cheers,
Bob
--
Bob Silverberg
www.silverwareconsulting.com