Hello,

i'm trying to build a "simple" query with ojb.

SELECT menu_links.*,it.cnt FROM menu_links, (SELECT 
menu_link_id,COUNT(*) AS cnt FROM logs GROUP BY menu_link_id ORDER BY 
COUNT(*) DESC) AS it WHERE menu_links.id = it.menu_link_id ORDER BY 
it.cnt DESC;

Basically select all Objects from menu_links where the id matches this 
query:

SELECT menu_link_id FROM logs GROUP BY menu_link_id ORDER BY COUNT(*) 
DESC LIMIT 10

I tried the following:

 ReportQueryByCriteria subQuery;
 Criteria subCrit = new Criteria();
 subCrit.addSql("LIMIT 10"); // does also not work without this
 subQuery = QueryFactory.newReportQuery(Log.class, subCrit);
 subQuery.setAttributes(new String[] { "menu_link_id"});
 subQuery.addGroupBy("COUNT(*)");

 Criteria crit = new Criteria();
 crit.addIn("id", subQuery);
 QueryByCriteria q = QueryFactory.newQuery(MenuLink.class, crit);

 Collection mls = dao.retrieve(q);

But i always get null.
Can anyone help me out on how to do this?

Christoph

Attachment: pgpptp6yUhm4d.pgp
Description: PGP signature

Reply via email to