【发布时间】:2015-01-02 16:08:29
【问题描述】:
我有一个使用 JPA 来管理数据库事务的 JSF 应用程序。
在我的数据结构中有 bills[Bill]。一张账单可以有多个账单项目[BillItem]。 Bill items 与 Item 有关系。票据可能有一个机构和一个收款中心。但在某些法案中两者都可以为空。我想按项目、机构和收集中心对账单项目进行分组并获取计数。以下 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());
【问题讨论】:
标签: mysql jpa group-by eclipselink jpql