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

Reference

http://docs.spring.io/spring-data/jpa/docs/1.10.6.RELEASE/reference/html/#jpa.modifying-queries

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

follow me on:

Leave a Comment: