I have the following scenario:
* Two distinct entity classes (A and B) are mapped to the same table
* Each entity class is mapped to distinct columns, except for two: the primary key, and another field that is updated by the database itself when the submit occurs, are both in each entity class
I have one method that does a find() on an instance of class A and updates it, and another method that does a find() and update on class B.
Within the same transaction context, I call the method that updates Class A with a given primary key, then I call the other method that updates Class B using the same primary key.
When there are updates to both entities I get a StaleObjectStateException - is there any way that I can update two entity classes mapped to the same row within the same transaction context?
I have tried a merge after updating the second bean, but that obviously doesn't work.
I got it!
One of the fields was annotated @Version afterall. I removed this annotation and could update multiple entities mapped to the same row and there was no exception.