Custom delete method in JpaRepository

984 views spring

I'd like to know if there's a way of overriding the delete method for some of my JpaRepository's without having to override the rest of the methods.

Currently I have something like

public interface UserRepo extends JpaRepository<User, Long>
    findUserById(long id);

    findUserByEmail(String email);

    // etc...

And I'd like to override the delete(T Entity) method in CrudRepository. To do so I've tried implementing the UserRepo but then I have to implement all the findByX and haven't really find anything around on how to properly do that.

Is there any annotation to add to a function in the Entity class so it runs when you call UserRepo.delete(myUser)?

Thanks in advance!

answered question

Please have a look into below issue somehow it related:…

1 Answer


In your case code will be like as below:

public interface UserRepo extends JpaRepository<User, Long> {

    deleteByEmail(@Param("email") String email);

posted this

Have an answer?


Please login first before posting an answer.