【问题标题】:JPA native query to find record of current dateJPA本机查询以查找当前日期的记录
【发布时间】:2019-08-22 23:42:34
【问题描述】:
@Query(value = "select * from Capping_Audit_Capture;\r\n"

        +"where datepart(year, captured_time) = ?2;\r\n"
        +"and datepart(month, captured_time) = ?3;\r\n"
        +"and datepart(day, captured_time) <= 1 and check_point_id=?4 and line_id=?5 ", nativeQuery = true)

这些查询有什么问题?我想获取当前日期的所有记录,得到异常

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: JPA 风格的位置参数不是一个完整的序数;嵌套异常是 java.lang.IllegalArgumentException: org.hibernate.QueryException: JPA-style positional param is not an integer ordinal

【问题讨论】:

    标签: spring-data-jpa


    【解决方案1】:

    您似乎在位置参数之后忘记了space。尝试将位置参数分号分开,如下例所示。

    @Query(value = "select * from Capping_Audit_Capture;\r\n"
    
            +"where datepart(year, captured_time) = ?2 ;\r\n"
            +"and datepart(month, captured_time) = ?3 ;\r\n"
            +"and datepart(day, captured_time) <= 1 and check_point_id=?4 and line_id=?5 ", nativeQuery = true)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2013-02-24
      相关资源
      最近更新 更多