【发布时间】:2021-01-08 00:30:25
【问题描述】:
我正在尝试限制 nativeQuery = true,但 Spring JPA 找不到此查询。
我的错误是:
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 ?那会是什么呢?
我在 Spring Boot 中的 Repository 的查询在哪里
@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);
【问题讨论】:
-
我想你在这里打错了
=: jobName LIMIT -
@T.Peter 谢谢。现在我得到了
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE data.jobName = 'Test3' LIMIT firstIndex = 0, selectedSamples = 104' at line 1,我尝试在Test3和LIMIT之间使用AND,但没有成功。 -
恳请您重新编辑评论中包含问题的帖子,以便新人发现实际问题。
-
另外
limit是一个用于设置SQL返回的元组数量上限的子句。我不认为limit是你想在这里做的。
标签: java sql spring spring-boot spring-data-jpa