{
ClassDescriptor cldProductGroup = broker.getClassDescriptor(ProductGroup.class);
ClassDescriptor cldArticle = broker.getClassDescriptor(Article.class);
Class productGroupProxy = cldProductGroup.getProxyClass();
Class articleProxy = cldArticle.getProxyClass();
CollectionDescriptor cds = cldProductGroup.getCollectionDescriptorByName("allArticlesInGroup");
//
// use ProductGroup and Articles with disabled Proxy
//
cldProductGroup.setProxyClass(null);
cldProductGroup.setProxyClassName(null);
cldArticle.setProxyClass(null);
cldArticle.setProxyClassName(null);
broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
broker.getDescriptorRepository().setClassDescriptor(cldArticle);
//
// orderby articleId, ASC
//
broker.clearCache();
cds.getOrderBy().clear();
cds.addOrderBy("articleId", true);
Criteria crit = new Criteria();
crit.addLessOrEqualThan("groupId", new Integer(5));
QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
q.addOrderByDescending("groupId");
q.addPrefetchedRelationship("allArticlesInGroup");
Collection results = broker.getCollectionByQuery(q);
assertNotNull(results);
assertTrue(results.size() == 5);
InterfaceProductGroup pg = (InterfaceProductGroup) results.toArray()[1];
assertNotNull(pg.getAllArticles());
Object articles[] = pg.getAllArticles().toArray();
int articleSize = articles.length;
assertTrue(articleSize == 10);
Article a1 = (Article) articles[0];
Article a2 = (Article) articles[9];
assertTrue(a1.getArticleId().intValue() < a2.getArticleId().intValue());
//
// orderby articleId, DESC
//
broker.clearCache();
cds.getOrderBy().clear();
cds.addOrderBy("articleId", false);
results = broker.getCollectionByQuery(q);
assertNotNull(results);
assertTrue(results.size() == 5);
pg = (InterfaceProductGroup) results.toArray()[1];