EhmKah EhmKah - 1 year ago 104
Java Question

SpringData Repository no exception for delete

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

so it won't throw an exception, if entity does not exsist?

Documentation clearly says it will.

Answer Source

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){

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download