You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Christoph Hermann <ch...@tu-clausthal.de> on 2005/02/13 18:00:17 UTC

Need help with (Report-) Query

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