EhmKah EhmKah - 3 months ago 8
Java Question

SpringData Repository no exception for delete

I am using SpringData's repository. Is there a way to modify default behavior of

delete(EntityId)
so it won't throw an exception, if entity does not exsist?

Documentation clearly says it will.

Answer

JavaDocs says that an IllegalArgumentException will be thrown if the provided argument (id, entity, Iterable<T>) is null and not if entity does not exsits.

If you need to avoid the IllegalArgumentException you could implement a custom delete method that checks id != null:

public void customDelete(ID id) {
    if(id != null){
        this.delete(id);
    }
}

Take a look to this docs section if you don't know how to add "Custom implementations for Spring Data repositories"

Comments