I'm not really even sure how to google this, so if it's a commonly asked question, please direct me to the answer.
A general description of the issue is that one or more parent records has a a set of child records of type 'Document'. The object graph is actually deeper and more complicated than that, but those are the relevant bits for my issue.
Generally we update the whole object graph with merge() when the user hits Save. But we have a requirement to save the Document record...AND ONLY the Document record as soon as they hit add or remove on the document. They can do as many add/removes as they want. There is no instant update, so when they want to update the description, that happens on the made 'Save'.
The instant update works fine. The problem is that on a later request, the user hits 'Save', thereby updating the parent and child records and if there was a remove during the process, I'm getting javax.persistence.EntityNotFoundException despite the fact that I DID remove the object from the set on it's parent.
On remove, I did this:
item.getDocuments().remove(document);
documentService.deleteDocumentByID(document.getId());
The first line removes it from the parent record, which i thought would notify hibernate not to freak out about my deleting it in the next like when I ran an HQL 'delete' on that ID.
Then, in the Save it's basically just a 'merge()' on the whole object graph.
Is there a way to make Hibernate okay with me adding/deleting JUST THAT DOCUMENT outside the merge()? Note that I do NOT want to save the whole object graph on that document add/remove. Just the document record.