Spring语句的SQL语句 - PersistentEntity不能为null

时间:2015-07-27 14:15:56

标签: mysql spring spring-data

我正在使用Spring Boot后端和AngularJS前端进行Web应用程序 数据库是MySQL 我尝试从我的数据库中获取前5项。我是通过这个做的 @Query Annotation。我直接在DB上尝试了我的SQL语句,得到了预期的值 SQL语句:

 select item 
    from work_item   
    group by item  
    order by count(*) desc   
    limit 3  

@Query:

@Query(value="SELECT WORK_ITEM_ITEM FROM WORK_ITEM GROUP BY WORK_ITEM_ITEM ORDER BY COUNT( *) DESC LIMIT 5", nativeQuery = true)  
List< String > find5MostUsedItems();

当我尝试访问相关网址时,我收到以下错误:

java.lang.IllegalArgumentException: PersistentEntity must not be null!

如果有人能把我推向正确的方向,我会很高兴 如果您需要更多信息,请询问。 (我的第一个问题:))

编辑:我的实体:

@Entity
public class WorkItem {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "workItem_ID")
    private long id;
    @Column(name = "workItem_date")
    private LocalDate date;
    @Column(name = "workItem_mitarbeiterNummer")
    private int mitarbeiterNummer;
    @Column(name = "workItem_startTime")
    private LocalTime startTime;
    @Column(name = "workItem_endTime")
    private LocalTime endTime;
    @Column(name = "workItem_workDuration")
    private int workDuration;
    @Column(name = "workItem_item")
    private String item;
    @Column(name = "workItem_itemDescription")
    private String itemDescription;

问候!

1 个答案:

答案 0 :(得分:0)

我认为你应该尝试SELECT WORKITEM_ITEM而不是SELECT WORK_ITEM_ITEM