我在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);
1条答案
按热度按时间vsikbqxv1#
在新方法的单独子查询后,它按预期工作,我认为这是Spring Data JPA的一个bug