【问题标题】:Parameter with that position [2] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position [2] did not exist具有该位置 [2] 的参数不存在;嵌套异常是 java.lang.IllegalArgumentException:具有该位置 [2] 的参数不存在
【发布时间】:2016-09-11 18:34:05
【问题描述】:

在执行异常时,我在 Spring Repository 中有以下方法是“具有该位置 [2] 的参数不存在”。我尝试了不同的选项来转义单引号('),希望问题仅在于这个。请提出建议。

@Query(value="select cus_acc_grp_i,"
            + " xmlquery ('$APP_CMP_WRK_XML/Root/CCPABusRuleAscList/CCPABusRuleAsc[position() >= (?2) and not(position() > (?3)) ]')"
            + " from ADM_APP_CMP_WRK  where CUS_ACC_GRP_I = (?1)", nativeQuery=true)
    AdministrationApplicationCompletion findCurrentPageRulesByClient(@Param("clientId") Integer customerAccountGroupId, 
            @Param("startIndex") Integer startIndex,
            @Param("endIndex") Integer endIndex);

【问题讨论】:

  • 我对 DB2 下的 XQuery 没有太多经验,但您似乎指的是第二个和第三个参数中的两个,而只注册了其中两个。

标签: sql spring db2 xquery spring-data-jpa


【解决方案1】:

@Smitha

你试试下面的怎么样:

@Query(value="select cus_acc_grp_i,"
            + " xmlquery ('$APP_CMP_WRK_XML/Root/CCPABusRuleAscList/CCPABusRuleAsc[position() >= (:startIndex) and not(position() > (:endIndex)) ]')"
            + " from ADM_APP_CMP_WRK  where CUS_ACC_GRP_I = (:customerAccountGroupId)", nativeQuery=true)
    AdministrationApplicationCompletion findCurrentPageRulesByClient(@Param("clientId") Integer customerAccountGroupId, 
            @Param("startIndex") Integer startIndex,
        @Param("endIndex") Integer endIndex);

请让我知道这是否有效:)

【讨论】:

  • 同样的错误;名称为 [startIndex] 的参数不存在;嵌套异常是 java.lang.IllegalArgumentException: 名为 [startIndex] 的参数不存在
  • 您可以尝试使用硬编码值在 db2 中运行查询吗?只是为了检查查询是否运行良好
  • 如果它运行正确,那么我会要求你跟进@Jens Erat 的建议
【解决方案2】:

我们不能直接在 XMLquery 标量函数中定义参数,必须在 xmlquery 中使用 PASSING 来传递参数。以下是解决方案。

SELECT XMLQUERY('//item[productName=$n]' PASSING PO.PO订单, CAST(@hv AS INTEGER) AS "n") AS "Result" FROM PurchaseOrders PO;

【讨论】:

    猜你喜欢
    • 2019-03-06
    • 1970-01-01
    • 2015-11-22
    • 2017-10-03
    • 2018-07-05
    • 1970-01-01
    • 2015-03-12
    • 2017-07-29
    • 2017-03-22
    相关资源
    最近更新 更多