Duplicate entry for key 'cwd_membership.uk_mem_dir_parent_child' error when restoring a backup

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Restoring a backup fails with the error

Unexpected error occurred during import: org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:Membership][lowerChildName,<username>][membershipType,GROUP_USER][parentName,<groupname>][childName,<username>][directoryId,<directoryid>][id,<membershipid>][childId,<userid>][lowerParentName,<groupname>][parentId,<groupid>] (SQL Exception while executing the following:INSERT INTO public.cwd_membership (ID, parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, directory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: duplicate key value violates unique constraint "uk_mem_dir_parent_child" Detail: Key (lower_parent_name, lower_child_name, membership_type, directory_id)=(<groupname>, <username>, GROUP_USER, <directoryid>) already exists.))

Diagnosis

The following error is observed in the Jira logs:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2024-01-01 00:00:00,000+0000 JIRA-Import-Thread-2 WARN [c.a.j.bc.dataimport.OfbizImportHandler] Create failed - retrying. Attempt [1] out of [5] org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:Membership][lowerChildName,<username>][membershipType,GROUP_USER][parentName,<groupname>][childName,<username>][directoryId,<directoryid>][id,<membershipid>][childId,<userid>][lowerParentName,<groupname>][parentId,<groupid>] (SQL Exception while executing the following:INSERT INTO public.cwd_membership (ID, parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, directory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: duplicate key value violates unique constraint "uk_mem_dir_parent_child" Detail: Key (lower_parent_name, lower_child_name, membership_type, directory_id)=(<groupname>, <username>, GROUP_USER, <directoryid>) already exists.)) at org.ofbiz.core.entity.GenericDAO.singleInsert(GenericDAO.java:211) at org.ofbiz.core.entity.GenericDAO.insert(GenericDAO.java:176) at org.ofbiz.core.entity.GenericHelperDAO.create(GenericHelperDAO.java:89) at org.ofbiz.core.entity.GenericDelegator.create(GenericDelegator.java:566) at org.ofbiz.core.entity.GenericDelegator.create(GenericDelegator.java:552) at org.ofbiz.core.entity.GenericValue.create(GenericValue.java:114) at com.atlassian.jira.bc.dataimport.OfbizImportHandler.createWithRetry(OfbizImportHandler.java:532) at com.atlassian.jira.bc.dataimport.OfbizImportHandler.lambda$createValue$0(OfbizImportHandler.java:510) at com.atlassian.jira.util.concurrent.BoundedExecutor$1.run(BoundedExecutor.java:50) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: org.ofbiz.core.entity.GenericDataSourceException: SQL Exception while executing the following:INSERT INTO public.cwd_membership (ID, parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, directory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (ERROR: duplicate key value violates unique constraint "uk_mem_dir_parent_child" Detail: Key (lower_parent_name, lower_child_name, membership_type, directory_id)=(<groupname>, <username>, GROUP_USER, <directoryid>) already exists.) at org.ofbiz.core.entity.jdbc.SQLProcessor.executeUpdate(SQLProcessor.java:591) at org.ofbiz.core.entity.GenericDAO.singleInsert(GenericDAO.java:203) ... 11 more

Cause

This error is caused by duplicate group membership entries in the entities.xml file, such as:

1 2 <Membership id="10000" parentId="10000" childId="10000" membershipType="GROUP_USER" parentName="TestGroup" lowerParentName="testgroup" childName="TestUser" lowerChildName="testuser" directoryId="1"/> <Membership id="10001" parentId="10000" childId="10000" membershipType="GROUP_USER" parentName="TestGroup" lowerParentName="testgroup" childName="TestUser" lowerChildName="testuser" directoryId="1"/>

Jira enforces uniqueness for group memberships on the combination of the parent group and child user/group names (case-insensitive), the membership type (group-to-user or group-to-group) and the directory ID.

In the above example, both group membership entries have the lowercased parent group name testgroup, the lowercased child username testuser, the membership type GROUP_USER and the directory ID 1, so they will be considered duplicates and cause the import to fail.

Solution

Unzip your backup file, find and remove the duplicate group membership entry from entities.xml, then rezip both activeobjects.xml and entities.xml into a new backup file and try restoring again.

Updated on March 18, 2025

Still need help?

The Atlassian Community is here for you.