我有一个JSF应用程序,它使用JPA来管理数据库事务。
在我的数据结构中有billsBill。一张账单可以有多个账单itemsBillItem。帐单项目与项目有关系。票据可能有一个机构和一个收款中心。但在某些法案中两者都是无效的。我想将条例草案的项目按项目、机构及收集中心分组,并计算数目。以下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 14:56:47
在关系之间使用一个点意味着内部连接,它将过滤掉空值。如果要允许关系中的空值,则必须显式地使用外部连接:
"Select count(bi) from BillItem bi JOIN bi.item item LEFT JOIN bi.bill bill LEFT JOIN bill.institution institution LEFT JOIN bill.collectingCentre collectingCentre group by item, institution, collectingCentre"https://stackoverflow.com/questions/26774608
复制相似问题