この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:1
ページ更新者:guest
更新日時:2019-04-08 10:41:31

タイトル: Not supported for DML operations
SEOタイトル: Not supported for DML operations【Springエラー】

エラー内容

Caused by: java.lang.RuntimeException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [UPDATE ... ];

nested exception is java.lang.IllegalStateException: org.hibernate.hql.internal.QueryExecutionRequestException: Not supported for DML operations [UPDATE ... ]

 

発生条件/原因/対処法

JPAで更新系のSQLを実行した際に発生するエラー。

更新系のメソッドに@Transactional がない もしくは @Transactional だけ付与されていると発生する。

以下のように@Modifyingを付与することで当エラーは解決する。

@Repository
public interface TestRepository extends JpaRepository<TestEntity, String>{
    
    @Transactional

    @Modifying
    @Query("UPDATE TestEntity te SET te.colA = 1 WHERE te.id = :id")
    Integer updateTest(@Param("id")String id);
}