Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Repository: get number of deleted rows

Tags:

spring-data

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?

like image 763
Etki Avatar asked Sep 30 '16 17:09

Etki


1 Answers

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.

like image 194
ksokol Avatar answered Nov 01 '22 23:11

ksokol