Sorry if this is a simplistic Q, I’m not strong with hibernate. We’re on hibernate 5.2. We have a large object graph queried when the page loads that includes a section with one to many. In that area we have a requirement to be able to add/delete rows, saving to the DB instantly, but with the rest of the object graph saved later (a different button, therefore different request, therefore different session…but same objects queried on load) via a merge().
When adding, everything seems fine. But when I delete a row, the merge (on the later request) fails with an entityNotFoundException on the key of the deleted row. I had removed the object from the DB by an HQL delete on the ID AND I removed it from the Set that the object graph stored it in. But Hibernate must have an additional store somewhere and remembers that the object existed, tries to get it as part of the merge, it’s not there and that makes Hibernate angry.
So I either need to know what the ‘right way’ to delete the entity to avoid this is, or need some way to inform Hibernate through the object graph that this object is gone and that’s intentional. but because other changes are being synched back to these objects I can’t reload the whole object graph nor can I update it all when doing the delete.
My google fu hasn’t really turned up a solution aimed at this.