code veda
code veda

Reputation: 125

How to solve error " error in your SQL syntax" in JPA for custom repository

I am developing an application with spring boot. While using JPA, i am getting error that error in SQL syntax.

public interface ReservoirRepository extends CrudRepository<Reservoir, Integer> {

    @Query(value = "From reservoir where patientID = ?1", nativeQuery = true)
    public List<Reservoir> findByPatientId(Integer patientId);
}

Here is the MySQL table and data

enter image description here

The error description is like this

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

Please help me i am not getting what's wrong here. Thanks :)

Upvotes: 0

Views: 418

Answers (1)

Madhav Kumar Jha
Madhav Kumar Jha

Reputation: 373

Write the full sql command, as its native query. Like @Query(value = "SELECT * FROM Reservoir res where res.patientID = ?1", nativeQuery = true)

Upvotes: 1

Related Questions