嗨,我正在构建一个REST服务,以使用JPA从PostgreSQL删除实体。代码是:
@Repository
public interface TestRepo extends JpaRepository<Question, Long>{
@Query(value = "delete from testmodel c where c.id in ?1 and c.name=?2",
nativeQuery = true)
void deleteModel(List<Long> ids, String text);
}
Run Code Online (Sandbox Code Playgroud)
代码工作正常,条目已从PostgreSQL中删除,但我在终端中收到以下异常。
org.postgresql.util.PSQLException: No results were returned by the query.
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:107) ~[postgresql-42.2.5.jar:42.2.5]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.2.0.jar:na]
Run Code Online (Sandbox Code Playgroud)
当我搜索此异常时,我建议使用executeUpdate而不是executeQuery。
由于我使用的是JPA,所以我不知道如何用executeUpdate替换executeQuery
任何帮助将是巨大的。
嗨,我已经编写了一个 Rest 服务来通过 RequestBody 接受长值列表作为输入,下面给出了相同的代码:
@DeleteMapping("/files")
public ResponseEntity<?> deletefiles(@RequestBody List<Long> ids) {
fileService.deleteSelectedfiles(ids);
return ResponseEntity.ok().build();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从 Postman 访问上述 url 时,出现以下错误:
"JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: [![enter image description here][1]][1]Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]"
Run Code Online (Sandbox Code Playgroud)
在邮递员中,我以以下格式将数据作为原始数据发送
{"ids": [1 ,2]}
Run Code Online (Sandbox Code Playgroud)
谁可以帮我这个事