antlr.NoViableAltException: unexpected token: limit 的解决方案

jpa项目出错的代码如下:

@Query(value = "select camera_id,count(camera_id) as num from t_ss_lljlb t where pullTime>=?1 and pullTime<=?2 and status<>200 group by camera_id order by num desc limit 3")
List getFailCameras(Date startTime, Date endTime);

控制台报错如下:

antlr.NoViableAltException: unexpected token: limit

原因是limit属于MySQL特有的特性,而@Query默认只接受通用SQL。

解决方法是简单地加上nativeQuery = true即可。如下:

@Query(value = "select camera_id,count(camera_id) as num from t_ss_lljlb t where pullTime>=?1 and pullTime<=?2 and status<>200 group by camera_id order by num desc limit 3",nativeQuery = true)
List getFailCameras(Date startTime, Date endTime);

你可能感兴趣的:(后端,数据库,#,java,java,sql,spring)