[英]Spring Data JPA - The statement did not return a result set
在我的应用程序中,我有一个在父/子关系中与自身相关的模型。 帖子可以有也是帖子的父母。 我写了一个查询来删除目标帖子及其后代。 当我在 Spring 之外执行查询时,它运行良好。 但是在 Spring 中运行时,查询执行成功但抛出以下异常:
WARN SqlExceptionHelper:144 - SQL Error: 0, SQLState: null
ERROR SqlExceptionHelper:146 - The statement did not return a result set.
ERROR [dispatcherServlet]:182 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet] with root cause
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
我的查询从扩展 JpaRepository 的接口运行
@Query(value = "WITH ParentTree AS (\n" +
" SELECT Parent.post_key,\n" +
" 1 AS Level\n" +
" FROM community_post AS Parent\n" +
" WHERE Parent.post_key = ?1\n" +
" UNION ALL\n" +
" SELECT Child.post_key,\n" +
" pt.Level + 1\n" +
" FROM community_post AS Child\n" +
" INNER JOIN ParentTree AS pt\n" +
" ON Child.post_parent = pt.post_key\n" +
" WHERE Child.post_parent IS NOT NULL\n" +
")\n" +
"DELETE FROM community_post\n" +
" WHERE post_key IN (\n" +
" SELECT post_key\n" +
" FROM ParentTree\n" +
" )", nativeQuery = true)
void recursiveDelete(long targetKey);
如果@Query缺少@Modifying注释,请添加它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.