Java “如何解决错误”;SQL语法中有错误“0”;在JPA中用于自定义存储库

Java “如何解决错误”;SQL语法中有错误“0”;在JPA中用于自定义存储库,java,mysql,spring-boot,jpa,spring-data-jpa,Java,Mysql,Spring Boot,Jpa,Spring Data Jpa,我正在用spring boot开发一个应用程序。在使用JPA时,我在SQL语法中遇到了这个错误 public interface ReservoirRepository extends CrudRepository<Reservoir, Integer> { @Query(value = "From reservoir where patientID = ?1", nativeQuery = true) public List<Reservoir> fi

我正在用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);
}

请帮帮我,我不明白这里出了什么问题。谢谢:)

编写完整的sql命令,作为其本机查询。喜欢
@Query(value=“SELECT*FROM treastory res,res.patientID=?1”,nativeQuery=true)

谢谢@Madhav,它成功了。如果你不介意的话,我想问一个问题。我只需要表中的level值,所以我像这样编写了公共接口ReservoirRepository扩展了crudepository{@Query(value=“Select res.reservoirId,res.level from res.patientID=?1和res.type=?2”,nativeQuery=true)公共列表findbypatientandtype(Integer patientID,Integer type);}但我得到了一个异常,声明“java.sql.SQLException:Column'patientID'notfound.”若你们能帮我得到这个,那个就太好了。谢谢,在上面的查询执行中,我得到了完整的库对象,包括患者对象,尽管我添加了注释@ManyToOne(fetch=FetchType.LAZY)@JsonIgnore@JoinColumn(name=“patientID”)private patient patient;水库级。那么为什么它不起作用呢?就您读取特定列而不是整行的需求而言,您现在的方式是不可能的,因为结果和java对象映射将不起作用。我没有具体的答案,只看这一个:对于第二个,我也没有任何具体的答案,特别是因为我看不到完整的声明和配置。同样,如果您关注过任何文章/博客,请重新检查您的实现,以检查是否缺少任何内容。或者浏览关于spring数据jpa延迟加载的文章
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