during a session.merge() I’m getting a
javax.persistence.EntityNotFoundException: No row with the given identifier exists Exception.
The business process is as follows:
- Client receives an object with it’s dependencies loaded by the server
- Client changes the dependencies (OneToMany) and sends it to the server
- Server tries to merge
I added the source code showing the problem here (~5kb)
doWork method leads to a unique constraint exception due to a item_id and language being a unique constraint and Hibernate doing the inserts before the deletes on flush.
doWork2 method leads to the aforementioned
javax.persistence.EntityNotFoundException: No row with the given identifier exists.
One way I found to fix the problem in
doWork2 is to remove the snapshots of the PersistantSet doing
((PersistentSet) item.getLabel()).setSnapshot(null, null, null);
The questions I have are now as follows:
- Is Hibernate meant to do the inserts before the deletes in method
- Will removing the snapshots on the PersistantSet have any strange sideeffects?
- Is there a better way to implement the given business process?
Note: We recently upgraded Hibernate from 3.6.4 to 5.2.12 and I think the exceptions didn’t occure back in the old version
Hope you can help me out, kind regards