postgresql Spring Data JPA SQL错误:0,SQLState:42601使用本地查询

5w9g7ksd  于 2023-06-29  发布在  PostgreSQL
关注(0)|答案(1)|浏览(280)

我在Spring中的原生查询有一个问题,它在SQL客户端中正常工作。但是,当存在WHERE语句时,它可以正常工作
查询失败

@Query(value = "SELECT a.id AS id, " +
        "a.key_1 AS key1, " +
        "a.key_2 AS key2, " +
        "a.total AS total, " +
        "a.modify_date AS modifyDate, " +
        "(SELECT COUNT(x.key_1) FROM book x WHERE x.key_1 = a.key_1) AS bookByKey1 " +
        "FROM book a", nativeQuery = true)
Optional<ResultDto> findAllByBookByKey1();

error说
SQL错误:0,SQLState:42601
错误:语法错误在“)”或附近
正常工作的查询

@Query(value = "SELECT a.id AS id, " +
        "a.key_1 AS key1, " +
        "a.key_2 AS key2, " +
        "a.total AS total, " +
        "a.modify_date AS modifyDate, " +
        "(SELECT COUNT(x.key_1) FROM book x WHERE x.key_1 = a.key_1) AS bookByKey1 " +
        "FROM book a WHERE a.key_2 LIKE %?1%", nativeQuery = true)
Page<ResultDto> findAllByBookByKey1(String key2);
vsikbqxv

vsikbqxv1#

在新方法的单独子查询后,它按预期工作,我认为这是Spring Data JPA的一个bug

相关问题