1
我的JPA接口,我有以下代碼:java的春天:意外的標記:*
public interface ConsultationRequestRepository extends CrudRepository<ConsultationRequest, Integer> {
@Query("select * from ConsultationRequest where status = ?1")
List<ConsultationRequest> findRequestsByStatus(ConsultationStatus status);
}
,但它與錯誤抱怨:
antlr.NoViableAltException: unexpected token: *
什麼錯誤代碼?
您需要使用HQL查詢sintax,不是SQL查詢到@Query註釋。假設ConsultationRequest是一個實體,hql查詢可能看起來像這樣:「SELECT cr FROM ConsultationRequest cr WHERE ...」。你可以看看http://docs.spring.io/spring-data/jpa/docs/current/reference/html/中的spring-jpa文檔,也可以鏈接到這個stackoverflow文章中的文檔:http:// stackoverflow.com/questions/6678591/create-query-in-hibernate。希望這有助於 –