Update single field using spring data jpa

You can try something like this on your repository interface:

@Modifying
@Query("update EARAttachment ear set ear.status = ?1 where ear.id = ?2")
int setStatusForEARAttachment(Integer status, Long id);

You can also use named params, like this:

@Modifying
@Query("update EARAttachment ear set ear.status = :status where ear.id = :id")
int setStatusForEARAttachment(@Param("status") Integer status, @Param("id") Long id);

The int return value is the number of rows that where updated. You may also use void return.

See more in reference documentation.

Leave a Comment