【问题标题】:How do I format a spring-data-jpa native query for postgres如何格式化 postgres 的 spring-data-jpa 本机查询
【发布时间】:2019-03-22 13:22:14
【问题描述】:

我正在尝试使用以下命令从 jpa 存储库中查询 postgres 数据库:

@Query(value =
    "SELECT " +
        "string_agg(distinct customer_po, ', ') as customer_po, " +
        "customer_part, " +
        "description, " +
        "bunzl_loc, " +
        "sum(dayspastexpected) as longestGrouping, " +
        "string_agg(distinct priority, ', '), " +
        "sum(open_qty) as totalBoQty, " +
        "sum(current_oh) as sunAvail, " +
        "next_receipt " +
    "FROM " +
        "sap_data.openorders_report " +
    "WHERE " +
        "run_date between :from and :to " +
    "AND " +
        "backorderorfuture = 'Future' " +
    "GROUP BY " +
        "customer_part, " +
        "bunzl_loc, " +
        "description, " +
        "next_receipt " +
    "ORDER BY " +
        "customer_part desc, " +
        "bunzl_loc desc /*#pageable*/",
    nativeQuery = true)
Page<SapOpenOrder> getBackOrderReport(@Param("from") Date from, @Param("to") Date to, Pageable pageable);

但我收到此错误:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "WHERE"

我可以在 dbeaver 中运行此查询并获得正确的结果。如何使用 spring jpa 运行此查询?

【问题讨论】:

    标签: spring-data-jpa nativequery


    【解决方案1】:

    如果您还没有,请更新到最新版本的 Spring Data JPA。 然后删除/*#pageable*/。 这是解决 Spring Data JPA 中的错误的一种方法,该错误现已修复。 详情请见https://jira.spring.io/browse/DATAJPA-928

    如果这不能解决问题,请使用实际执行的 SQL 语句更新您的问题。 在为 JPA 实现配置日志记录后,您可以从日志中获取该语句。

    【讨论】:

      猜你喜欢
      • 2019-06-21
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 2018-12-14
      • 2017-04-21
      • 1970-01-01
      相关资源
      最近更新 更多