Suppose in a table ‘Foo’ I have a foreign key ‘barId’ to some table ‘Bar’. What I want to do is update an existing entry in ‘Foo’ by setting barId=null, and automatically delete the previously associated Bar entry.
In JPA, is it possible to automatically declare and accomplish this via annotations?
Or do I have to make a separate call to barRepository.delete(...) to delete the old Bar object? (while saving the updated Foo object)
I believe this is handled by JPA’s “orphan removal”: http://docs.oracle.com/cd/E19798-01/821-1841/giqxy/index.html