我试着限制自己 nativeQuery = true
但是springjpa找不到这个查询。
我的错误是:
Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract void se.danielmartensson.repositories.DataRepository.deleteByJobNameOrderByDateTimeLimit(java.lang.String,long,long) but parameter 'Optional[jobName]' not found in annotated query 'DELETE FROM Data data ORDER BY data.dateTime WHERE data.jobName =: jobName LIMIT firstIndex = :firstIndex, selectedSamples = :selectedSamples'!
所以我猜 LIMIT
应该有不同的属性,而不是 firstIndex
以及 selectedSamples
? 那会是什么呢?
我的问题从哪里来 Repository
Spring Boot
@Query(value = "SELECT * FROM Data data ORDER BY data.dateTime WHERE data.jobName = :jobName LIMIT firstIndex = :firstIndex, selectedSamples = :selectedSamples", nativeQuery = true)
List<Data> findByJobNameOrderByDateTimeLimit(@Param("jobName") String jobName, @Param("firstIndex") long firstIndex, @Param("selectedSamples") long selectedSamples);
@Modifying
@Query(value = "DELETE FROM Data data ORDER BY data.dateTime WHERE data.jobName =: jobName LIMIT firstIndex = :firstIndex, selectedSamples = :selectedSamples", nativeQuery = true)
void deleteByJobNameOrderByDateTimeLimit(@Param("jobName") String jobName, @Param("firstIndex") long firstIndex, @Param("selectedSamples") long selectedSamples);
2条答案
按热度按时间4ioopgfo1#
如果你只是想知道
jobName
以及firstIndex
以及selectedSamples
匹配参数。您应该使用正确的sql语法并将它们放入where
.正确的语法如下:
vngu2lb82#
我创建了一个使用
H2
. 你必须改变limit
以及offset
您正在使用的数据库的一部分。对于delete操作,有delete from table where id in (select id from table where .. order by .. limit .. offset ..)
已定义。注:
Lombok
用于getter
,setter
以及toString
. 它不是必需的。数据存储库.java
数据.java
试验
输出
mysql数据库
为了
mysql
删除操作成功,脚本如下。参考:mysql delete from with subquery as condition-answer