Hi Nishant,

First off, unless your Subscription Type is rather dynamic, you might
want to consider using an enum for it (especially if you are using
3.0):

http://cayenne.apache.org/doc/modeling-enumerations.html

Next, it sounds like what you are wanting is a list of magazines for a
given user.  Instead of starting at the user, you could start at the
magazines and put the sort order on it.  You essentially want to:
fetch magazines where subscriptions.readers.rname = your_reader order
by mname.

In Cayenne, it would be more like (and I'm guessing at your
relationship/attribute names):

Expression exp = Expression.fromString("subscriptions.readers.rname = $reader");
Map param = new HashMap(1);
param.put("reader", "reader's name");
SelectQuery query = new SelectQuery(Magazine.class,
exp.expWithParameters(param));
Ordering order = new Ordering(Magazine.MNAME_PROPERTY, true);
query.addOrdering(order);
List<Magazine> magazines = dataContext.performQuery(query);

mrg


On Sun, Sep 13, 2009 at 4:55 AM, Nishant Neeraj <[email protected]> wrote:
> I am having problem in sorting and paginating  many to many relationship 
> objects.
> Here is the DB relationship model.  http://i30.tinypic.com/jaz4wm.jpgI want 
> to do Readers.getMagzines() that returns paginated resultset of page size, N.
>
> I write a Readers.getMagzine() Method that pulls out List of subscriptions. 
> In the method, I iterate through the list and inflating Magzines 
> (subscriptions.getMagzines()) and injecting SubscriptionType to magzine 
> object. And then I return the list. This works fine.
> Now, I do not want to pull out the full list. Rather, I want do it page by 
> page sort by say, MagzineName with page Size N. Not sure how to do it. Can 
> some one give a hint?
> ThanksNishant
>
>
>      Love Cricket? Check out live scores, photos, video highlights and more. 
> Click here http://cricket.yahoo.com

Reply via email to