在JPQL中获取类

时间:2014-08-04 15:00:10

标签: jpa jpql

在JPA应用程序中,Bill类已扩展为BilledBill,CancelledBill和RefundBill。

有一个JPQL查询,列出了类别名称,项目名称等,如下所示。

        String jpql = "select c.name, i.name, count(bi.bill), sum(bf.feeValue), bf.fee.feeType "
            + " from BillFee bf join bf.billItem bi join bi.item i join i.category c  "
            + " where bi.bill.institution=:ins "
            + " and bi.item.department.institution=:ins "
            + " and  bi.bill.billType= :bTp  "
            + " and  bi.bill.createdAt between :fromDate and :toDate "
            + " and (bi.bill.paymentMethod = :pm1 "
            + " or  bi.bill.paymentMethod = :pm2 "
            + " or  bi.bill.paymentMethod = :pm3 "
            + " or  bi.bill.paymentMethod = :pm4)"
            + " group by i.name, c.name, bf.fee.feeType "
            + " order by c.name, i.name, bf.fee.feeType";

    temMap.put("toDate", toDate);
    temMap.put("fromDate", fromDate);
    temMap.put("ins", institution);
    temMap.put("bTp", BillType.OpdBill);
    temMap.put("pm1", PaymentMethod.Cash);
    temMap.put("pm2", PaymentMethod.Card);
    temMap.put("pm3", PaymentMethod.Cheque);
    temMap.put("pm4", PaymentMethod.Slip);

    List<Object[]> lobjs = getBillFacade().findAggregates(jpql, temMap, TemporalType.TIMESTAMP);

我想按类分组并在select语句中获取类。这可能吗?

1 个答案:

答案 0 :(得分:0)

如果您有discriminator column,则可以。

假设您的鉴别器列是名为String的{​​{1}}字段。您应该添加到您的实体:

DTYPE

现在您可以在@Column(name = "DTYPE") private String clazz; // .. // getter

中使用它了
JPQL Query