What are the rules about saving an object multiple times?

I’m building some tests for our code, and ran into a situation in which I created an Obs, saved it, modified it, saved it again. I got this error when I ran the test:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.openmrs.Obs#43]

I’ve have other code where I changed existing objects and this hasn’t happened, so I am trying to figure out what is different in this case.

Some things I’ve looked at so far: I’ve verified that there aren’t, somehow, other objects with that id, and I’ve tried putting Context.flush() after the first write, and that didn’t help.

Any ideas what I should be looking for?

I wrote up something about this kind of error ~4 years ago. Hope it helps!

https://wiki.openmrs.org/x/GREz