JPAを使用している間はPostgresで例外「該当する結果がクエリによって返されませんでした」の解決方法

クリシュナ:

こんにちは私はJPAを使用してのPostgreSQLからエンティティを削除するには、RESTサービスを構築しています。そして、コードは次のとおりです。

@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);
}

コードが正常に動作している、エントリは、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]

私はこの例外で検索すると、私は、のexecuteUpdateの代わりにexecuteQueryを使用するための提案を得ました。

私はJPAを使用していますので、私はのexecuteUpdateでのexecuteQueryを交換する方法がわかりません

すべてのヘルプはGREATFULだろう。

Elgayed:

あなたは追加する必要があり@Modifying、それが更新クエリであることを宣言するために、あなたはDBからの結果の背中を期待していません

@Repository
public interface TestRepo  extends JpaRepository<Question, Long>{
    @Modifying
    @Query(value = "delete from testmodel c where c.id in ?1 and c.name=?2",
            nativeQuery = true)
    void deleteModel(List<Long> ids, String text);
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=230260&siteId=1