如何在条件构建器中创建JPA多重计数?

时间:2017-05-03 01:39:52

标签: java sql hibernate jpa

我正在使用JPA条件构建器为失败的邮件和总邮件创建两个计数。我没有得到如何在JPA中采取两项计数。我试过这两种方法,但是我收到了一些错误。

//1st way
Root<sourceTracking> u = cq.from(sourceTracking.class);
Expression<sourceTracking> status=u.get("delivery_status");
List<sourceTracking> columns=new ArrayList<sourceTracking>();
columns.add((sourceTracking) u.get("mail_server"));
columns.add((sourceTracking) cb.count(cb.selectCase().when(cb.equal(status, "deferred"), 1L)));
columns.add((sourceTracking) cb.count(u));
cq.multiselect(columns);
//here multiselect getting error

//2nd way
cq.multiselect(u.<String>get("mail_server"),cb.sum(cb.selectCase()
.when(cb.equal(u.<String>get("delivery_status"), "deferred"),1)
.otherwise(0)),cb.count(u)).groupBy(u.<String>get("mail_server"));
//here sum getting error

0 个答案:

没有答案