Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java spring : unexpected token: *

Tags:

java

spring

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?

like image 611
Jeff Avatar asked Nov 23 '16 14:11

Jeff


2 Answers

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

like image 51
eparvan Avatar answered Nov 03 '22 14:11

eparvan


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);
}
like image 26
Tim Weber Avatar answered Nov 03 '22 14:11

Tim Weber