Spring Repository: get number of deleted rows
11,126
Create a repository method with the @Modifying
annotation as described here:
@Modifying
@Query("delete from data where createdAt < ?1")
int retainDataBefore(Date retainDate);
Return value gives you the count of deleted rows.
Comments
-
Etki almost 2 years
I'm in need of getting count of deleted rows by Spring Repository custom query (i'm implementing basic external lock mechanism for application and is limited to MySQL database only). How can i achieve that?
-
maxxyme over 2 yearsSimilar to what's described here: docs.spring.io/spring-data/jpa/docs/current/reference/html/…
-
P.Sanjay about 2 yearsUse :1 instead of ?1. Like @Query("delete from DETAILS where ID = :1")