NonUniqueObjectException accessing obs from encounter

Hello All,

I’m facing the NonUniqueObjectException mentioned in our wiki. I’m trying to compare the values of an observation and if anything has changed i’m trying to save the value here where the exception is being thrown. I’ve been through many mailing list topics related to this by @wyclif, @darius and @bwolfe. And also this trunk issue.

But, i’m unable to correlate it to the issue as it occurs only when two instances of the same ID exist and we are trying to save one of them. I can only imagine the one object to be ‘o’ and other object with the same id to be present in the encounter as a part of collection. Any suggestions on how I can find a workaround for this ? @darius, @wyclif ?

@maurya can you share the stack trace?

@darius, stack trace -

Are you able to create a unit test that reproduces the problem?

Apologies,I managed to solve the issue I think the error might be because I’ve been trying to save observations multiple times without any modifications.

I made a mistake in checking the uuids(me comparing the uuid’s of obs and concept uuids instead of comparing uuids of concepts under obs and concept uuids), after correcting it and saving the whole encounter, the database changes are being cascaded to observations as well.

I originally tried saving the whole encounter but even after the encounter being saved, the change to observations were not happening, hence my branching out to saving singular observations where the error originated.

Thanks for looking into it @darius and @dkayiwa.

Maurya I am actually confused with the explanation you gave here. I am interested to know the scenario because I think I will encounter it sooner or later. Do you think you can elaborate? Thanks.

Apologies @willa,

So basically I made a mistake of comparing the concept ID’s with obs ID’s while trying to modify the observations if they changed, which didn’t make any changes when I successfully saved an encounter having the observations.

This led me to trying to save singular observations by trying to access them from an encounter, in this case I think this creates two different copies of the same object one exists in the encounter observations, and one that I’m trying to save, this throws the exception saying there are two different objects with the same id and Hibernate is not sure which copy to save.

This can be solved by either

  • accessing an encounter, getting observations in it, modifying them and saving the encounter having a copy of each observation with it.
  • accessing a singular observation through ObsService and saving it instead of getting an encounter and saving an observation. (which is what I have been trying and getting the exception)
  • using a Merge in Hibernate instead of SaveOrUpdate (not advisable while using a module)
1 Like