Sometimes itβs quite difficult (or a performance problem) to delete all references to an object.
For example, I have a Person object that is related to other Person objects.
When I delete a Person, I do not want to delete this Person in all respects that it may have simply because sometimes this Person object does not know what it refers to. Therefore, if I want to remove all links, I have to do additional sql work, which can lead to performance problems.
In an ideal world, I would like to remove the Person object, and when another person made a reference to this Person (because it has its id in its relationship), just return null.
The fact is that the JPA complains that
javax.persistence.EntityNotFoundException: No row with the given identifier exists
Is there a way to force JPA to return a null reference, and not an exception in this case?
source share