Directory Synchronisation with Crowd fails regarding duplicate entries in database

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

Symptoms

The directories synchronisation will not work due to duplicate entries in the database. This could be due to a possible corruption with the directory. When you try to synchronise the external directories under Confluence Admin > User Directories, the following appears in the atlassian-confluence.log:

1 2 3 4 5 6 7 INFO [http-8443-31] [embedded.admin.list.DirectoriesController] sync User directory synchronisation requested: [ Crowd Server ], type: [ CROWD ] INFO [scheduler_Worker-5] [atlassian.crowd.directory.DbCachingRemoteDirectory] synchroniseCache synchronisation for directory [ xxxx ] starting ERROR [scheduler_Worker-5] [sf.hibernate.util.JDBCExceptionReporter] logExceptions Duplicate entry 'xxxxx' for key 'cwd_unique_user_membership' ERROR [scheduler_Worker-5] [sf.hibernate.impl.SessionImpl] execute Could not synchronize database state with session INFO [scheduler_Worker-5] [atlassian.crowd.directory.DbCachingRemoteDirectory] synchroniseCache failed synchronisation complete in [ 40ms ] ERROR [scheduler_Worker-5] [atlassian.crowd.directory.DbCachingDirectoryPoller] pollChanges Error occurred while refreshing the cache for directory [ xxxxx ]. org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert: com.atlassian.crowd.embedded.hibernate2.HibernateMembership#xxxx; SQL []; Duplicate entry 'xxxx' for key 'cwd_unique_user_membership'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'xxxxx' for key 'cwd_unique_user_membership'

Cause

A group membership is trying to be synchronised from the remote directory which already exists. When Confluence is trying to add the directory (again) the synchronisation will not be allowed, since duplicate entries are found.

Workaround

Flushing the cache of the directory will stop the error from happening, and cause the directory to synchronise fully, until the next time a duplicate group membership is sent from the remote directory. The simplest way of forcing this is:

  1. Disable the directory

  2. Enable the directory

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.