2
在我的應用程序中,我有一個與父/子關係本身相關的模型。帖子可以有也是帖子的父母。我寫了一個查詢來刪除一個目標文章及其後代。當我在Spring之外執行查詢時,它完美地工作。然而,在春季運行它時,查詢成功執行,但會引發以下異常:Spring Data JPA - 聲明沒有返回結果集
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);
「@修改」與'@ Transactional'一起做了訣竅。非常感謝! –
太棒了!樂於幫助。 – unigeek