尝试调用 JPA 函数时出现语法错误

当我尝试调用 JPA 函数时,这条语句出现错误:“:”处或附近的语法错误


 public interface BcaTestRepository extends CrudRepository<InBodyBCA, Long> {

  @Query(value = "SELECT * FROM in_body_bca bca WHERE person_id = :personId " +

      "AND to_timestamp(bca.datetimes::text, 'YYYYMMDDHH24MISS')  BETWEEN :startRange AND :endRange",

      nativeQuery = true)

  List<InBodyBCA> findAllByPersonId(@Param("personId") Long personId,

                                    @Param("startRange") LocalDateTime startRange,

                                    @Param("endRange") LocalDateTime endRange);


但在 PgAdmin 中查询工作正常


SELECT id, to_timestamp(datetimes::text, 'YYYYMMDDHH24MISS') as dt FROM in_body_bca WHERE to_date(datetimes::text, 'YYYYMMDDHH24MISS')

BETWEEN '2018-05-07' AND '2019-05-07' ORDER BY to_date(datetimes::text, 'YYYYMMDDHH24MISS') DESC ;


墨色风雨
浏览 126回答 1
1回答

慕码人8056858

您在这里使用双冒号:bca.datetimes::text。JPA 会寻找text变量名。你需要逃避它:bca.datetimes\\:\\:text
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java