0
我有一个使用JPA来管理数据库事务的JSF应用程序。JPQL不分组空值
在我的数据结构中有账单[Bill]。一张账单可以有很多账单项目[BillItem]。帐单项目与项目有关系。票据可能有一个机构和一个收集中心。但是在一些账单中这两者都可以为空。我希望按条目,机构和收集中心对条例草案进行分组并统计。以下jpql仅列出具有Institutions和Collecting Centers的那些jpql。这意味着它不会将空值分组。
我使用EclipseLink 2.4和MySQL。
String jpql;
Map m = new HashMap();
jpql = "Select new com.divudi.data.dataStructure.ItemInstitutionCollectingCentreCountRow(bi.item, bi.bill.institution, bi.bill.collectingCentre, count(bi)) "
+ " from BillItem bi "
+ " where bi.bill.createdAt between :fd and :td "
+ " and type(bi.item) =:ixbt "
+ " and bi.retired=false "
+ " and bi.bill.retired=false "
+ " and bi.bill.cancelled=false "
+ " and bi.retired=false ";
jpql = jpql + " group by bi.item, bi.bill.institution, bi.bill.collectingCentre";
jpql = jpql + " order by bi.bill.institution.name, bi.bill.collectingCentre.name, bi.item.name ";
m.put("fd", fromDate);
m.put("td", toDate);
m.put("ixbt", Investigation.class);
insInvestigationCountRows = (List<ItemInstitutionCollectingCentreCountRow>) (Object) billFacade.findAggregates(jpql, m, TemporalType.DATE);
System.out.println("sql = " + jpql);
System.out.println("m = " + m);
System.out.println("insInvestigationCountRows.size() = " + insInvestigationCountRows.size());
谢谢!现在查询返回空组的记录。 – 2014-11-06 18:41:12