the groupBy information is defined in the query not in the criteria, so the copy() does not make much sense. but there's a problem when counting reportqueries using groupBy:
Criteria crit = new Criteria();
ReportQueryByCriteria q = QueryFactory.newReportQuery(ProductGroup.class, crit);
q.setColumns(new String[] { "groupName", "sum(allArticlesInGroup.stock)", "sum(allArticlesInGroup.price)" });
q.addGroupBy("groupName");
broker.getReportQueryIteratorByQuery(q);
while (iter.hasNext())
{
results.add(iter.next());
}int count = broker.getCount(q); assertEquals(results.size(), count); <<< FAILS
results in this sql:
SELECT A0.KategorieName,sum(A1.Lagerbestand),sum(A1.Einzelpreis) FROM Kategorien A0 LEFT OUTER JOIN BOOKS A1 ON A0.Kategorie_Nr=A1.Kategorie_Nr LEFT OUTER JOIN CDS A1E2 ON A0.Kategorie_Nr=A1E2.Kategorie_Nr LEFT OUTER JOIN Artikel A1E1 ON A0.Kategorie_Nr=A1E1.Kategorie_Nr GROUP BY A0.KategorieName
ojb generates a wrong count-sql :
SELECT count(*) FROM Kategorien A0
or when including groupBy:
SELECT count(*),A0.KategorieName as ojb_col_1 FROM Kategorien A0 GROUP BY A0.KategorieName
how should the count look like (without using a subquery) ?
jakob
Danilo Tommasina wrote:
Hi,
Is there a reason why the GroupBy clause is beeing ignored in a query when doing a PersistenceBorker.getCount( Query query )?
In RC4 release I found this piece of code:
class PersistenceBokerImpl
public int getCount(Query query) throws PersistenceBrokerException {
(...)
// build a ReportQuery based on query // orderby needs to be cleared if (query.getCriteria() != null) { reportCrit = query.getCriteria().copy(false, false, false); }
(...)
}
The line:
reportCrit = query.getCriteria().copy(false, false, false);
copies the Criteria ignoring the GroupBy clause, thus causing the count query to return a wrong number of elements.
Is there a reason for this or has it been fixed after RC4?
thx bye Danilo
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
