-
Bug
-
Resolution: Fixed
-
Medium
-
3.5.9
-
None
-
SQL Server, Oracle
Problem description
Importing XML backup that contains page restrictions will fail with ConstraintViolationException:
2011-08-10 10:34:40,674 ERROR [Importing data task] [confluence.importexport.xmlimport.BackupImporter] importEntities Cannot import the entities: -- referer: http://localhost:8359/setup/setup-restore-start.action | url: /setup/setup-restore.action | userName: anonymous | action: setup-restore com.atlassian.confluence.importexport.ImportExportException: Unable to complete import because the data does not match the constraints in the Confluence schema. Cause: SQLException: Violation of UNIQUE KEY constraint 'cp_unique_user_groups'. Cannot insert duplicate key in object 'dbo.CONTENT_PERM'. at com.atlassian.confluence.importexport.xmlimport.DefaultXmlImporter.doImport(DefaultXmlImporter.java:57) at com.atlassian.confluence.importexport.xmlimport.BackupImporter.importEntities(BackupImporter.java:237) at com.atlassian.confluence.importexport.xmlimport.BackupImporter.importEverything(BackupImporter.java:181) at com.atlassian.confluence.importexport.xmlimport.FileBackupImporter.importEverything(FileBackupImporter.java:108) at com.atlassian.confluence.importexport.xmlimport.BackupImporter.doImportInternal(BackupImporter.java:108) at com.atlassian.confluence.importexport.Importer.doImport(Importer.java:74) at com.atlassian.confluence.importexport.DefaultImportExportManager.importAs(DefaultImportExportManager.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy83.importAs(Unknown Source) at com.atlassian.confluence.importexport.actions.ImportLongRunningTask.runInternal(ImportLongRunningTask.java:55) at com.atlassian.confluence.util.longrunning.ConfluenceAbstractLongRunningTask.run(ConfluenceAbstractLongRunningTask.java:21) at java.lang.Thread.run(Thread.java:662) Caused by: net.sf.hibernate.exception.ConstraintViolationException: could not insert: [com.atlassian.confluence.security.ContentPermission#753668] at com.atlassian.confluence.importexport.xmlimport.parser.BackupParser.endElement(BackupParser.java:53) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source) at javax.xml.parsers.SAXParser.parse(SAXParser.java:198) at com.atlassian.confluence.importexport.xmlimport.DefaultXmlImporter.parseBackup(DefaultXmlImporter.java:93) at com.atlassian.confluence.importexport.xmlimport.DefaultXmlImporter.doImport(DefaultXmlImporter.java:45) ... 20 more Caused by: net.sf.hibernate.exception.ConstraintViolationException: could not insert: [com.atlassian.confluence.security. #753668] at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:62) at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29) at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1331) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:472) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436) at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2447) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2433) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2390) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2259) at com.atlassian.confluence.importexport.xmlimport.ImportProcessorContext.flushIfNeeded(ImportProcessorContext.java:212) at com.atlassian.confluence.importexport.xmlimport.ImportProcessorContext.saveObject(ImportProcessorContext.java:256) at com.atlassian.confluence.importexport.xmlimport.persister.ReflectiveObjectPersister.persist(ReflectiveObjectPersister.java:119) at com.atlassian.confluence.importexport.xmlimport.DefaultImportProcessor.persist(DefaultImportProcessor.java:42) at com.atlassian.confluence.importexport.xmlimport.DefaultImportProcessor.processObject(DefaultImportProcessor.java:32) at com.atlassian.confluence.importexport.xmlimport.parser.BackupParser.endElement(BackupParser.java:49) ... 33 more Caused by: java.sql.SQLException: Violation of UNIQUE KEY constraint 'cp_unique_user_groups'. Cannot insert duplicate key in object 'dbo.CONTENT_PERM'. at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368) at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816) at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254) at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631) at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584) at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546) at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105) at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:462) ... 45 more
Cause
In Confluence 3.4.x or earlier, we don't check NULL value of CPS_ID under CONTENT_PERM table. We do that in 3.5.x or higher.
Patch
Attached is a patch to address this issue that is known to work for Confluence 3.5.9 or later. It may work with 3.5.0-3.5.8, but that has not been tested.
Contents
The patch contains 26 files in the following directories:
- confluence/WEB-INF/classes/
- upgradeSubsystemContext.xml
- com/atlassian/confluence/core/DefaultContentPermissionManager.class
- com/atlassian/confluence/core/persistence/hibernate/ConfluenceHibernateConfig.class
- com/atlassian/confluence/importexport/xmlimport/DefaultObjectPersisterFactory.class
- com/atlassian/confluence/importexport/xmlimport/persister/
- HibernateMembershipPersister.class
- PersisterOperations.class
- 3x ReflectiveObjectPersister classes
- com/atlassian/confluence/security/
- ContentPermission.hbm.xml
- ContentPermissionSet.hbm.xml
- com/atlassian/confluence/upgrade/ddl/
- AlterTableExecutor.class
- DdlExecutor.class
- com/atlassian/confluence/upgrade/upgradetask/
- AddBandanaConstrantsUpgradeTask.class
- 4x BandanaKeyUniqueConstraintCleaner classes
- 7x ContentPermissionConstraintsCleaner classes
- ContentPermissionConstraintsUpgradeTask.class
Installation
Before installing, ensure that your backup xml zip is current. This install will remove all existing data from the database, and only use whatever you load via the backup.
To install, you can:
- Stop Confluence
- Extract the patch into your <confluence install dir>. This will create various directories under <confluence install dir>/confuence/WEB-INF/classes.
- Delete your old <confluence home dir>.
- Start Confluence, and during setup, select "Restore From Backup", and restore the backup zip you which to install.
Alternatively, you can:
- Stop Confluence
- Extract the patch into your <confluence install dir>. This will create various directories under <confluence install dir>/confuence/WEB-INF/classes.
- Start Confluence
- Browse to "Confluence Admin > Backup & Restore", and restore the backup zip you which to install.
- causes
-
CONFSERVER-22567 Import from 3.4.5 to 3.5.4 fails with "unique constraint violation"
- Closed
- is related to
-
CONFSERVER-23425 XML Import fails with Oracle Constraint Violation
- Closed
-
CONFSERVER-23058 Constraint violation failure when importing on SQL Server due to content permission nulls
- Closed
- relates to
-
CONFSERVER-24031 Bad constraints on SQL Server
- Closed