Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Java 无法迭代查询返回的值_Java_Spring_Hibernate_Spring Boot - Fatal编程技术网

Java 无法迭代查询返回的值

Java 无法迭代查询返回的值,java,spring,hibernate,spring-boot,Java,Spring,Hibernate,Spring Boot,我试图从本机查询中检索值,但如果返回的类型为Object[]。我收到一个打字错误。如果我把它设为biginger[]我只得到一个值 @Query(value = "select coalesce(sum(individual),0) as individual, coalesce(sum(groups),0) as groups, coalesce(sum(habitation),0) as habitation, coalesce(sum(works),0) as work

我试图从本机查询中检索值,但如果返回的类型为
Object[]
。我收到一个打字错误。如果我把它设为
biginger[]
我只得到一个值

    @Query(value = "select  coalesce(sum(individual),0) as individual, 
    coalesce(sum(groups),0) as groups, coalesce(sum(habitation),0) as habitation, coalesce(sum(works),0) as works,"+
        "  coalesce(sum(others),0) as others,"+
        "  coalesce(sum(online),0) as online, coalesce(sum(standalone),0) as standalone, coalesce(sum(excel),0) as excel, coalesce(sum(manual),0) as manual,"+
        "  coalesce(sum(working),0) as working, coalesce(sum(not_working),0) as not_working, coalesce(sum(under_development),0) as under_development,"+
        "  coalesce(sum(nic),0) as nic, coalesce(sum(cgg),0) as cgg, coalesce(sum(portal_others),0) as portal_others"+
        " from( select dept_id,scheme_id, sub_scheme_id,"+
        "      case when beneficiary_type = 1 then 1 else 0 end as individual,"+
        "      case when beneficiary_type = 2 then 1 else 0 end as groups,"+
        "      case when beneficiary_type = 4 then 1 else 0 end as habitation,"+
        "      case when beneficiary_type = 5 then 1 else 0 end as works,"+
        "      case when beneficiary_type = 6 then 1 else 0 end as others,"+
        "      case when system_type = 1 then 1 else 0 end as online,"+
        "      case when system_type = 2 then 1 else 0 end as standalone,"+
        "      case when system_type = 3 then 1 else 0 end as excel,"+
        "      case when system_type = 4 then 1 else 0 end as manual,"+
        "      case when system_type = 1 and system_status = 1 then 1 else 0 end as working,"+
        "      case when system_type = 1 and system_status = 2 then 1 else 0 end as not_working,"+
        "      case when system_type = 1 and system_status = 3  then 1 else 0 end as under_development,"+
        "      case when system_type = 1 and software_developed_by = '1' then 1 else 0 end as cgg,"+
        "      case when system_type = 1 and software_developed_by = '2' then 1 else 0 end as nic,"+
        "      case when system_type = 1 and (software_developed_by = '0' or  software_developed_by = '99') then 1 else 0 end as portal_others"+
        "    from scheme_details " +
        "    where is_deleted is false"+
        "  )t", nativeQuery = true)
public BigInteger[] queryWithCaseValues();

因此,为了检索字段,我必须进行大量转换

 Object[] schemeDetailValues = (Object[])schemeDetailCount[0];
    BigInteger[] retrieveValues = retrieveschemeDetailValues(schemeDetailValues);
        adminDashboardCommand.setIndividualBeneficiaryCount(retrieveValues[0].intValue());
        adminDashboardCommand.setGroupBeneficiaryCount(retrieveValues[1].intValue());
        adminDashboardCommand.setHabitationBeneficiaryCount(retrieveValues[2].intValue());
        adminDashboardCommand.setWorksBeneficiaryCount(retrieveValues[3].intValue());
        adminDashboardCommand.setOthersBeneficiaryCount(retrieveValues[4].intValue());
        adminDashboardCommand.setTotalBeneficiaryCount(retrieveValues[5].intValue());
        adminDashboardCommand.setOnlineSystemsAvailableCount(retrieveValues[6].intValue());
        adminDashboardCommand.setStandaloneSystemsAvailableCount(retrieveValues[7].intValue());
        adminDashboardCommand.setExcelUploadSystemAvailableCount(retrieveValues[8].intValue());
        adminDashboardCommand.setManualSystemsAvailableCount(retrieveValues[9].intValue());
        adminDashboardCommand.setTotalSystemsAvailableCount(retrieveValues[10].intValue());
        adminDashboardCommand.setWorkingSystemsCount(retrieveValues[11].intValue());
        adminDashboardCommand.setNonWorkingSystemsCount(retrieveValues[12].intValue());
        adminDashboardCommand.setUnderDevelopmentSystemsCount(retrieveValues[13].intValue());
        adminDashboardCommand.setNicWebsiteCount(retrieveValues[14].intValue());
        adminDashboardCommand.setCggWebsiteCount(retrieveValues[15].intValue());
        adminDashboardCommand.setOthersWebsiteCount(retrieveValues[16].intValue());
        adminDashboardCommand.setTotalWebsiteCount(retrieveValues[17].intValue());
所以我对Spring数据如何简化开发感到困惑。似乎只有对于简单的映射,JPA才有用。当涉及到本机查询时,需要进行大量的数据转换。有人能告诉我为什么这么多企业在复杂性增加时使用它,就像使用JDBC一样好吗

谢谢,
Manoj

因此,为了检索字段,我必须进行大量转换

 Object[] schemeDetailValues = (Object[])schemeDetailCount[0];
    BigInteger[] retrieveValues = retrieveschemeDetailValues(schemeDetailValues);
        adminDashboardCommand.setIndividualBeneficiaryCount(retrieveValues[0].intValue());
        adminDashboardCommand.setGroupBeneficiaryCount(retrieveValues[1].intValue());
        adminDashboardCommand.setHabitationBeneficiaryCount(retrieveValues[2].intValue());
        adminDashboardCommand.setWorksBeneficiaryCount(retrieveValues[3].intValue());
        adminDashboardCommand.setOthersBeneficiaryCount(retrieveValues[4].intValue());
        adminDashboardCommand.setTotalBeneficiaryCount(retrieveValues[5].intValue());
        adminDashboardCommand.setOnlineSystemsAvailableCount(retrieveValues[6].intValue());
        adminDashboardCommand.setStandaloneSystemsAvailableCount(retrieveValues[7].intValue());
        adminDashboardCommand.setExcelUploadSystemAvailableCount(retrieveValues[8].intValue());
        adminDashboardCommand.setManualSystemsAvailableCount(retrieveValues[9].intValue());
        adminDashboardCommand.setTotalSystemsAvailableCount(retrieveValues[10].intValue());
        adminDashboardCommand.setWorkingSystemsCount(retrieveValues[11].intValue());
        adminDashboardCommand.setNonWorkingSystemsCount(retrieveValues[12].intValue());
        adminDashboardCommand.setUnderDevelopmentSystemsCount(retrieveValues[13].intValue());
        adminDashboardCommand.setNicWebsiteCount(retrieveValues[14].intValue());
        adminDashboardCommand.setCggWebsiteCount(retrieveValues[15].intValue());
        adminDashboardCommand.setOthersWebsiteCount(retrieveValues[16].intValue());
        adminDashboardCommand.setTotalWebsiteCount(retrieveValues[17].intValue());
所以我对Spring数据如何简化开发感到困惑。似乎只有对于简单的映射,JPA才有用。当涉及到本机查询时,需要进行大量的数据转换。有人能告诉我为什么这么多企业在复杂性增加时使用它,就像使用JDBC一样好吗

谢谢,
Manoj

您能给我们提供有关类型转换的异常详细信息吗?(stacktrace)java.lang.ClassCastException:[Ljava.lang.Object;无法强制转换为java.math.BigInteger。当我将方法作为公共对象[]queryWithCaseValues();将方法更改为:公共对象[]queryWithCaseValues()时会发生这种情况;提供一个包含错误的完整示例。您的查询返回多个列,因此它们无法明显映射到1 BigInteger。您可以为我们提供有关类型转换的异常详细信息吗?(stacktrace)java.lang.ClassCastException:[Ljava.lang.Object;无法转换为java.math.BigInteger。当我将该方法作为公共对象[]时会发生这种情况queryWithCaseValues();将方法更改为:public Object[]queryWithCaseValues();提供一个包含错误的完整示例。您的查询返回多个列,因此它们无法映射到1个BigInteger