gpt4 book ai didi

java - Spring Data JPA @Query 注解,nativeQuery = true,

转载 作者:行者123 更新时间:2023-11-29 04:47:57 25 4
gpt4 key购买 nike

我的@Repository有问题:

@Repository
public interface RekvZmRepository extends CrudRepository<RekvalZamestn, RekvalZamestnPk> {
@Query(value = "SELECT z.* FROM rek_zm d INNER JOIN proj_a a ON d.id = a.prj_idcislo"
+ " INNER JOIN proj_e e ON a.id = e.id"
+ " INNER JOIN rekv_z z ON d.id = z.id"
+ "WHERE d.id = ?1 AND a.id = ?2 AND e.id = ?3", nativeQuery = true)
public List<RekvalZamestn> getRekvOsOnDoh(Long dhzmrk, Long prj, Long prje);
}

当我运行它时,结果是:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not
extract ResultSet; SQL [n/a]; nested exception is
org.hibernate.exception.SQLGrammarException: could not extract ResultSet

当我运行 SQL 时,它可以正常工作,所以对我来说,问题不在于 SQL,而在于我的 @Query

最佳答案

您的查询,以单行格式(由于 erm,空格的原因将多个空格压缩为一个空格)等同于

SELECT z.* FROM rek_zm d INNER JOIN proj_a a ON d.id = a.prj_idcislo INNER JOIN proj_e e ON a.id = e.id INNER JOIN rekv_z z ON d.id = z.idWHERE  d.id = ?1 AND a.id = ?2 AND e.id = ?3

如果像这样将所有字符串连接在一行中,很明显您在 WHERE 子句之前缺少一个空格。

关于java - Spring Data JPA @Query 注解,nativeQuery = true,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36433246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com