thanks for help Michael,
It still does not work, I try with a in Memory, but no difference ...
this is my latest version:
Expression exp = ExpressionFactory.matchExp(patientid, "1234");
query = new SelectQuery(Patient.class, exp);
query.addPrefetch(_Patient.STUDIES_PROPERTY);
// query.addOrdering("studies.studydt", true); // nice but not work,
however the sql request is ok, but certainely the fetch problem!!
List patients = context.performQuery(query);
// So, now I try a in Memory sort: For each patient, I get all his
studies and try or order them by "studydate" (the getter or study.class),
//
for (int i = 0; i < patients.size(); i++) {
Patient p = (Patient) patients.get(i);
Ordering ordering = new Ordering("studydate", true); //
Instead of the getter studydate I tried with studydt (obj-entity
attribute) but no diff
ordering.orderList(p.getStudies());
}
any idea ?
thanks
arnaud
Gentry, Michael (Contractor) a écrit :
>Ah, the orderings only apply to the returned object(s). In your case,
>you are asking for a Patient with an ID of 1234. Only one object is
>coming back in your List. Your studies will be prefecthed, but will be
>in "random" order (to the best of my knowledge).
>
>The easiest way to handle this is to add a cover method in your subclass
>(the non-underscore Patient.java) to do an in-memory sort of the studies
>and use that method to get them in the order you want.
>
>Look at
>http://www.objectstyle.org/cayenne/userguide/fetch/orderings.html to see
>how to do the in-memory sort.
>
>/dev/mrg
>
>
>-----Original Message-----
>From: Arnaud Garcia [mailto:arnaud.garci..im.hcuge.ch]
>Sent: Wednesday, August 31, 2005 10:10 AM
>To: cayenne-use..bjectstyle.org
>Subject: ordering and path expression
>
>
>Hi,
>
>I would like to know how to use the ordering function with path
>expression in my queries.
>My objects are "Patient.class" with a list of "study.class" objects wich
>
>has a studydate getter (a simple one to many relationship)
>
>I want to retrieve my patients (by ID) with all the studies ordering by
>date (the date is a filed of Study.class),
>
>My code:
> Expression exp = ExpressionFactory.matchExp(patientid, "1234");
> query = new SelectQuery(Patient.class, exp);
> query.addPrefetch(studies);
> query.addOrdering(".....???...", true); // maybe something
>like: toPatient.study.studydate
> List patients = context.performQuery(query);
>
>many thanks for help
>
>arnaud
>
>
>
>
This archive was generated by hypermail 2.0.0 : Wed Aug 31 2005 - 12:03:39 EDT