Social Media

Spring Data JPA – @Query – Not supported for DML operations

I was wanting to update a database table status with a list of ID’s so decided the simplest way was to use @Query and JPAQL –

When I ran the code I got this exception –

The reason is the code is calling execute, and we need executeUpdate. The fix is fairly simple – you add the @Modifying annotation –

The @Modifying annotaion is used to instruct spring-data that this is a “modifying-query”, and allow DML operations


About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment:

1 comment
khoadv42 says 27/04/2019

thanh you very much

Add Your Reply