Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA: How to create "delete by multiple properties" method?

I want to delete an entity(ies) by multiple entity properties?

I know how to do it using JPA query (@Query annotation).

Is It possible to do it using derived query? How to name such method in JpaRepository?

like image 463
Michal Foksa Avatar asked Oct 07 '16 18:10

Michal Foksa


1 Answers

It is straight forward as naming select method:

Two properties:

long deleteByIdAndUser(
    @Param("id") Long id, 
    @Param("user") User user);

Three properties:

long deleteByIdAndUserAndStatus(
    @Param("id") Long id, 
    @Param("user") User user, 
    @Param("status") String status);

etc.

like image 87
Michal Foksa Avatar answered Oct 19 '22 11:10

Michal Foksa