我正在使用 Spring Boot 开发一个应用程序。使用 JPA 时,我收到 SQL 语法错误。
public interface ReservoirRepository extends CrudRepository<Reservoir, Integer> {
@Query(value = "From reservoir where patientID = ?1", nativeQuery = true)
public List<Reservoir> findByPatientId(Integer patientId);
}
这是MySQL表和数据
错误描述是这样的
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From reservoir where patientID = 1' at line 1
请帮助我,我没有明白这里出了什么问题。谢谢:)
最佳答案
编写完整的 sql 命令,作为其 native 查询。喜欢 @Query(value = "SELECT * FROM Reservoir res where res. PatientID = ?1", nativeQuery = true)
关于java - 如何解决自定义存储库 JPA 中的错误 "error in your SQL syntax",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59335684/