I am trying to detect changes made to the entity before commiting the transaction. I'm successufully using the following algorithm:
1. Clone managed entity to a new one by copying all the arrtibutes
2. Refresh the managed entity to lose all the changes
3. Compare these objects to see where changes occured
4. Merge the cloned entity so that the changes were saved eventually
This artificial detaching single entity is working great for me, but not when entityManager uses FlushModeType.MANUAL. In that mode merging throws
Code:
StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
Can anyone help me bypass that?