简体   繁体   English

java spring:意外令牌:*

[英]java spring : unexpected token: *

In my jpa interface, i have the following code: 在我的jpa界面中,我有以下代码:

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 有关使用@Query注释的更多信息,请点击此处

Never forget that JPA is not SQL , even if there is similar expression. 永远不要忘记JPA不是SQL ,即使有类似的表达式。
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 : 您希望获取所有条目并将其放入POJO或列表中,因此您必须在select子句中指定它,如下所示:

public interface ConsultationRequestRepository extends CrudRepository<ConsultationRequest, Integer> {

    @Query("select c from ConsultationRequest c where status = ?1")
    List<ConsultationRequest> findRequestsByStatus(ConsultationStatus status);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM