Restoring space fails since the user is already present in the target instance with a different user_key
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
Space import will fail and the error mentioned below can be noticed in the application log.
1
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert duplicate key row in object 'dbo.user_mapping' with unique index 'user_mapping_unq_lwr_username'. The duplicate key value is (<test>).
Environment
This issue can occur in any of the Confluence server and Datacenter versions.
Diagnosis
There are no duplicate users found in the source database and in the XML export entities.xml file. Mentioned below is the error snippet in the application log.
1 2 3 4 5 6 7 8 9 10 11 12 13
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement ... Caused by: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:245) ... Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112) ... Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert duplicate key row in object 'dbo.user_mapping' with unique index 'user_mapping_unq_lwr_username'. The duplicate key value is (test). at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:260) at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1547) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:528) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPrepared
Instead, the same user was present in the target Confluence instance but with a different user_key. This can be verified by running the SQL statement against both source and destination Confluence databases. The username should be captured from the error stack trace accordingly.
1
select * from user_mapping where username='<username>'
1 2
The user in the source Confluence instance has the user_key - 8a7f80897349910a01734e6f2cf000f6 The same user in the target Confluence instance has the user_key - 8ad681ba7980e59e017986284c6b0000
Cause
Space import will fail if the same user is already present in the target Confluence database with a different user_key.
Solution
If indeed the same user is already present in the target Confluence database then we need to follow the steps mentioned below to fix the issue.
Unzip the XML export
Update the entities.xml file
1 2 3 4 5
From: <id name="key"><![CDATA[8a7f80897349910a01734e6f2cf000f6]] ></id> To: <id name="key"><![CDATA[8ad681ba7980e59e017986284c6b0000]] ></id>
Re-zip the export
Import the updated XM export in the target Confluence instance.
Was this helpful?