In my jpa interface, i have the following code:
public interface ConsultationRequestRepository extends CrudRepository<ConsultationRequest, Integer> {
@Query("select * from ConsultationRequest where status = ?1")
List<ConsultationRequest> findRequestsByStatus(ConsultationStatus status);
}
but it complains with the error:
antlr.NoViableAltException: unexpected token: *
what is wrong in this code?
Try to change your query in the following way:
@Query("select c from ConsultationRequest c where c.status = ?1")
Or you can use native query:
@Query("select * from ConsultationRequest where status = ?1", nativeQuery = true)
More about using @Query
annotation you can find here
Never forget that JPA is not SQL, even if there is similar expression.
You want to get all entries and put it into a POJO or a list so you have to specify it in your select clause, like this :
public interface ConsultationRequestRepository extends CrudRepository<ConsultationRequest, Integer> {
@Query("select c from ConsultationRequest c where status = ?1")
List<ConsultationRequest> findRequestsByStatus(ConsultationStatus status);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With