Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa &引用;“在什么情况下”;总额内条款_Jpa_Jpql_Criteria Api_Case When - Fatal编程技术网

Jpa &引用;“在什么情况下”;总额内条款

Jpa &引用;“在什么情况下”;总额内条款,jpa,jpql,criteria-api,case-when,Jpa,Jpql,Criteria Api,Case When,我的表/实体如下所示: *ID* | *Description* | *Error* | *batchId* 1 | test 111 | 0 | 456 2 | test 222 | 1 | 456 3 | test 333 | 0 | 456 4 | test xxx | 1 | 458 5 | test yyy | 1 | 458 我正在尝试选择此表

我的表/实体如下所示:

*ID* | *Description* | *Error* | *batchId*
  1  | test 111      |    0    | 456
  2  | test 222      |    1    | 456
  3  | test 333      |    0    | 456
  4  | test xxx      |    1    | 458
  5  | test yyy      |    1    | 458
我正在尝试选择此表单中的结果:

batchId | HowManyOK | HowManyErrors 
   456  |     2     |       1
   458  |     0     |       2
在JPQL中,我尝试过:

SELECT 
   g, 
   SUM( CASE WHEN g.error = false THEN 1 ELSE 0 END ) AS ok, 
   SUM( CASE WHEN g.error = false THEN 1 ELSE 0 END ) AS ko  
FROM
   GoogleMerchantLog g 
GROUP BY g.batchId
但是它没有编译!它在总和处声明错误“封装的表达式不是有效表达式”

也许有一些建议可以用标准API来解决这个问题

没有解决方案?
我最终解决了映射本机查询的问题:((

这是我刚刚编写的代码:

@Query("SELECT new be.mteam.zoomit.persistence.vo.ZoomitValidation(Z.organization, " +
            "Z.documentType, " +
            "Z.language, " +
            "Z.recipientProfil, " +
            "Z.documentDate, " +
            "sum(case when(Z.status = be.mteam.zoomit.persistence.vo.ZoomitStatus.WAITVALIDATION) then 1 else 0 end), " +
            "sum(case when(Z.status = be.mteam.zoomit.persistence.vo.ZoomitStatus.WAITTOSEND " +
            "or Z.status = be.mteam.zoomit.persistence.vo.ZoomitStatus.POSTED " +
            "or Z.status = be.mteam.zoomit.persistence.vo.ZoomitStatus.CREATED " +
            "or Z.status = be.mteam.zoomit.persistence.vo.ZoomitStatus.SENDING) then 1 else 0 end), " +
            "sum(case when(Z.status = be.mteam.zoomit.persistence.vo.ZoomitStatus.SENT) then 1 else 0 end)) " +
        "from Zoomit as  Z " +
        "where Z.organization = :organization " +
            "and Z.status in (be.mteam.zoomit.persistence.vo.ZoomitStatus.WAITVALIDATION," +
            "be.mteam.zoomit.persistence.vo.ZoomitStatus.WAITTOSEND," +
            "be.mteam.zoomit.persistence.vo.ZoomitStatus.POSTED," +
            "be.mteam.zoomit.persistence.vo.ZoomitStatus.CREATED," +
            "be.mteam.zoomit.persistence.vo.ZoomitStatus.SENDING," +
            "be.mteam.zoomit.persistence.vo.ZoomitStatus.SENT) " +
        "group by Z.organization, Z.documentType, Z.language, Z.recipientProfil, Z.documentDate")
List<ZoomitValidation> getValidations(@Param("organization") String organization);
致:

马文:

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.2.5.RELEASE</version>
org.springframework.data
spring数据jpa
2.2.5.1发布

PS:没有找到使用statics import来缩短ZoomitStatus枚举的方法。

如何在没有
SUM()
方法的情况下尝试使用just
CASE,并确保使用
JPA 2.x
版本。但是…通过删除SUM()可以,我不会得到组的总和,我只会得到1或0?@FabioB。你是不是很幸运地解决了它…不!我想我走了另一条路。我记不清了,对不起。
SELECT 
   g.batchId, 
   SUM(CASE WHEN (g.error = false) THEN 1 ELSE 0 END) AS ok, 
   SUM(CASE WHEN (g.error = true) THEN 1 ELSE 0 END) AS ko  
FROM
   GoogleMerchantLog g 
GROUP BY g.batchId
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.2.5.RELEASE</version>