Mysql JPQL没有对空值进行分组
我有一个JSF应用程序,它使用JPA来管理数据库事务 在我的数据结构中有Bill[Bill]。一张票据可以有多个票据项目[BillItem]。账单项目与项目之间存在关系。票据可以有一个机构和一个托收中心。但在某些票据中,两者都可以为空。我想按项目、机构和收款中心对账单项目进行分组,并获得计数。以下jpql仅列出了设有机构和收集中心的机构。这意味着它不将空值分组 我使用EclipseLink 2.4和MySQLMysql JPQL没有对空值进行分组,mysql,jpa,group-by,eclipselink,jpql,Mysql,Jpa,Group By,Eclipselink,Jpql,我有一个JSF应用程序,它使用JPA来管理数据库事务 在我的数据结构中有Bill[Bill]。一张票据可以有多个票据项目[BillItem]。账单项目与项目之间存在关系。票据可以有一个机构和一个托收中心。但在某些票据中,两者都可以为空。我想按项目、机构和收款中心对账单项目进行分组,并获得计数。以下jpql仅列出了设有机构和收集中心的机构。这意味着它不将空值分组 我使用EclipseLink 2.4和MySQL String jpql; Map m = new HashMap();
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());
stringjpql;
Map m=新的HashMap();
jpql=“选择新建com.divudi.data.dataStructure.ItemInstitutionCollectionCentreControw(bi.item,bi.bill.institution,bi.bill.CollectionCentre,count(bi))”
+“来自BillItem bi”
+“其中bi.bill.createdAt介于:fd和:td之间”
+“和类型(bi.项)=:ixbt”
+“and bi.retired=false”
+“和bi.bill.retired=false”
+“和bi.bill.cancelled=false”
+“and bi.retired=false”;
jpql=jpql+“按bi.item、bi.bill.institution、bi.bill.collectingcenter分组”;
jpql=jpql+“按bi.bill.institution.name、bi.bill.collectingcenter.name、bi.item.name排序”;
m、 put(“fd”,自日期起);
m、 put(“td”,toDate);
m、 put(“ixbt”,调查类);
InInvestigationCountRows=(列表)(对象)billFacade.findAggregates(jpql,m,TemporalType.DATE);
System.out.println(“sql=“+jpql”);
System.out.println(“m=”+m);
System.out.println(“InInvestigationCountRows.size()=”+InInvestigationCountRows.size());
在关系之间使用点表示一个内部联接,它将过滤掉空值。如果要在关系中允许空值,则必须显式使用外部联接:
"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"
非常感谢。现在,查询返回具有空组的记录。