Error while importing Metadata Sharing package containing PersonAttributeTypes

Hi guys !

I have some trouble to import an MDS package that contains only Person Attribute Types.

Here is the error message:

org.openmrs.module.metadatasharing.task.TaskException: Task failed
  at org.openmrs.module.metadatasharing.task.Task.log(
  at org.openmrs.module.metadatasharing.task.TaskEngine$
  at java.util.concurrent.ThreadPoolExecutor.runWorker(
  at java.util.concurrent.ThreadPoolExecutor$
Caused by: org.openmrs.module.metadatasharing.task.TaskException: Task failed
  ... 4 more
Caused by: org.openmrs.module.metadatasharing.task.TaskException: Import failed


Caused by: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [org.openmrs.PersonAttributeType#2]


See in full here

Steps to reproduce:

1/ Create a blank OpenMRS Platform

with the OpenMRS SDK, based on

  • Core 2.1.0 SNAPSHOT

Add the minimal set of modules such as:

  • legacyui-1.3.1.omod
  • metadatasharing-1.2.2.omod
  • metadatamapping-1.3.2.omod

2/ Export MDS package

Export a metadata sharing package with all the Person Attribute Types that come by default on the new server:

Admin -> Export Metadata -> Create Package -> Name it “PersonAttributeType” -> Add metadata to package -> Select ‘PersonAttributeType / All’ -> Export

Confirm that the export goes through without error:

3/ Import MDS package

Admin -> Import Metadata -> Import package -> Select your file ‘PersonAttributeType’ -> Choose ‘From Master’ as import mode -> Next -> Next -> Import

Now I get the error detailed above in the message.

I have failed to reproduce this. Are you able to reproduce it with any released (non snapshot) version of the platform?

I am trying now. In the mean time, I was able to reproduce this on the Bahmni demo. Not sure if it helps.

I can reproduce this bug with Core 2.1.0 too (thanks @dkayiwa for the Source Forge link)

Thanks for the perseverance! I have reproduced it too. It happens only from 2.1 and above. @raff have you ever seen this?

Could I see the full stacktrace from server logs?

@raff Here is the server log.

@raff FWIW, i did some investigation and discovered that it is caused by this line:

As a result of this commit:

In other words, if that line is commented out, then all is well

@mksrom can you create a platform ticket for this?


Thanks @dkayiwa for looking into that. I’ll comment on the issue.

I have attached some unit tests on the ticket to reproduce this. It is caused by PersonService.savePersonAttributeType() which clears the entire hibernate session. As a result, any hibernate object that was previously loaded will result into a NonUniqueObjectException on trying to save it.

@mksrom I have failed to reproduce the error on platform 2.3.2. Am stack at

What is the source of package ZIP File to be imported? I have tried to check for PersonAttributeType file inside the cloned core but I can’t see it. Am only seeing `PersonServiceTest-PersonAttributeType.xml which is not our scope.

I don’t recall exactly I must say, but the source file is probably the Zip file you’ve just exported in Step 2. That shouldn’t be an xml file

Thanks for your response let me try it out.

@mksrom I have imported the zip file I exported in step 2 and this is what I have as an output

In relation to this ticket and the above results what is your take on the way forward of the issue ? Was the error limited to 2.1.0 version only or 2.1.0 and above version because I have used version 2.3.2.

Thanks in advance.

Seems like it works fine then. I have never tried on 2.3.2 I must say.


You are right 2.3.2 is a maintenance release of 2.3.x line which is not released officially because of some blockers but since am the one releasing it, I can’t shy away from using it :slightly_smiling_face: