Unable to Delete Confluence Spaces [Confluence Server]
Asked by Basilio:

Hi fellows,  

I'm trying to delete 2 spaces, but I'm facing an error.  

Basically these spaces are empty and we will no more need them.  

This is a piece of log that I'm analyzing, but I was unable to solve the problem.  

If you have any tip to share, please send me.

\*I altered the url and username, but the user who attempted to delete them has the necessary permissions  

Kindly regards

```
2018-01-29 10:21:36,753 ERROR [Long running task: Space removal long running task] [atlassian.confluence.event.ConfluenceEventDispatcher] run There was an exception thrown trying to dispatch event [com.atlassian.confluence.event.events.space.SpaceRemoveEvent[source=com.atlassian.confluence.spaces.DefaultSpaceManager@6d837cee]] from the invoker [com.atlassian.confluence.event.ConfluenceListenerHandlersConfiguration$TimingListenerHandler$1$1@379c8217]
 -- space: 14712848 | url: /spaces/doremovespace.action | traceId: 4087126f9d7c5c5e | userName: sysadmin | referer: http://confluence.com.br/spaces/removespace.action?key=B2BARQ | action: doremovespace
java.lang.RuntimeException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.atlassian.confluence.spaces.Space#14712848]
 at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:41)
 at com.atlassian.confluence.event.ConfluenceListenerHandlersConfiguration$TimingListenerHandler$1$1.invoke(ConfluenceListenerHandlersConfiguration.java:69)
 at com.atlassian.confluence.event.ConfluenceEventDispatcher$VCacheRequestContextRunnableFactory$1.lambda$run$0(ConfluenceEventDispatcher.java:93)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$doInRequestContext$0(VCacheRequestContextOperations.java:50)
 at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:87)
 at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:71)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.doInRequestContext(VCacheRequestContextOperations.java:49)
 at com.atlassian.confluence.event.ConfluenceEventDispatcher$VCacheRequestContextRunnableFactory$1.run(ConfluenceEventDispatcher.java:93)
 at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:299)
 at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:88)
 at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:203)
 at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:114)
 at com.atlassian.confluence.event.TimingEventPublisher.publish(TimingEventPublisher.java:64)
 at com.atlassian.confluence.spaces.DefaultSpaceManager.removeSpace(DefaultSpaceManager.java:197)
 at com.atlassian.confluence.spaces.DefaultSpaceManager.removeSpace(DefaultSpaceManager.java:160)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
 at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at com.atlassian.confluence.util.profiling.ConfluenceMonitoringMethodInterceptor.invoke(ConfluenceMonitoringMethodInterceptor.java:34)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
 at com.sun.proxy.$Proxy114.removeSpace(Unknown Source)
 at com.atlassian.confluence.api.impl.service.longtasks.tasks.SpaceRemovalLongRunningTask.runInternal(SpaceRemovalLongRunningTask.java:36)
 at com.atlassian.confluence.util.longrunning.ConfluenceAbstractLongRunningTask.run(ConfluenceAbstractLongRunningTask.java:26)
 at com.atlassian.confluence.util.longrunning.ManagedTask.run(ManagedTask.java:52)
 at com.atlassian.confluence.impl.util.concurrent.ConfluenceExecutors$ThreadLocalContextTaskWrapper.lambda$wrap$1(ConfluenceExecutors.java:90)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$doInRequestContext$0(VCacheRequestContextOperations.java:50)
 at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:87)
 at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:71)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.doInRequestContext(VCacheRequestContextOperations.java:49)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$withRequestContext$2(VCacheRequestContextOperations.java:66)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:748)
Caused by: javax.persistence.EntityNotFoundException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.atlassian.confluence.spaces.Space#14712848]
 at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:126)
 at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
 at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1419)
 at com.atlassian.confluence.setup.bandana.persistence.dao.hibernate.HibernateConfluenceBandanaRecordDao.lambda$findKeysForContext$4(HibernateConfluenceBandanaRecordDao.java:89)
 at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:359)
 at org.springframework.orm.hibernate5.HibernateTemplate.execute(HibernateTemplate.java:313)
 at com.atlassian.confluence.setup.bandana.persistence.dao.hibernate.HibernateConfluenceBandanaRecordDao.findKeysForContext(HibernateConfluenceBandanaRecordDao.java:86)
 at com.atlassian.confluence.setup.bandana.ConfluenceDaoBandanaPersister.retrieveKeys(ConfluenceDaoBandanaPersister.java:49)
 at sun.reflect.GeneratedMethodAccessor1998.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
 at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
 at com.sun.proxy.$Proxy56.retrieveKeys(Unknown Source)
 at com.atlassian.confluence.setup.bandana.ConfluenceCachingBandanaPersister.retrieveKeys(ConfluenceCachingBandanaPersister.java:113)
 at com.atlassian.bandana.DefaultBandanaManager.getKeys(DefaultBandanaManager.java:54)
 at sun.reflect.GeneratedMethodAccessor1762.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
 at com.sun.proxy.$Proxy503.getKeys(Unknown Source)
 at sun.reflect.GeneratedMethodAccessor1762.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
 at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
 at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
 at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
 at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
 at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
 at com.sun.proxy.$Proxy1229.getKeys(Unknown Source)
 at com.atlassian.confluence.plugins.createcontent.listeners.RemoveSpaceListener.onSpaceRemoveEvent(RemoveSpaceListener.java:22)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:32)
 ... 45 more
2018-01-29 10:21:36,754 WARN [hipchat-plugin-tasks-executor-0] [hipchat.spacetoroom.service.DefaultHipChatSynchronisationProcessor] run Unable to synchronise with HipChat because the link has been removed.
2018-01-29 10:21:36,759 WARN [Long running task: Space removal long running task] [confluence.impl.hibernate.ConfluenceHibernateTransactionManager] doRollback Performing rollback. Transactions:
 ->[com.atlassian.confluence.spaces.DefaultSpaceManager.removeSpace]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT (Session #1177468842)
 -- space: 14712848 | url: /spaces/doremovespace.action | traceId: 4087126f9d7c5c5e | userName: sysadmin | referer: http://confluence.com.br/spaces/removespace.action?key=B2BARQ | action: doremovespace
2018-01-29 10:21:36,765 ERROR [Long running task: Space removal long running task] [confluence.util.longrunning.ConfluenceAbstractLongRunningTask] run Long running task "Space removal long running task" failed to run.
 -- space: 14712848 | url: /spaces/doremovespace.action | traceId: 4087126f9d7c5c5e | userName: sysadmin | referer: http://confluence.com.br/spaces/removespace.action?key=B2BARQ | action: doremovespace
org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
 at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
 at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
 at com.sun.proxy.$Proxy54.commit(Unknown Source)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485)
 at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at com.atlassian.confluence.util.profiling.ConfluenceMonitoringMethodInterceptor.invoke(ConfluenceMonitoringMethodInterceptor.java:34)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
 at com.sun.proxy.$Proxy114.removeSpace(Unknown Source)
 at com.atlassian.confluence.api.impl.service.longtasks.tasks.SpaceRemovalLongRunningTask.runInternal(SpaceRemovalLongRunningTask.java:36)
 at com.atlassian.confluence.util.longrunning.ConfluenceAbstractLongRunningTask.run(ConfluenceAbstractLongRunningTask.java:26)
 at com.atlassian.confluence.util.longrunning.ManagedTask.run(ManagedTask.java:52)
 at com.atlassian.confluence.impl.util.concurrent.ConfluenceExecutors$ThreadLocalContextTaskWrapper.lambda$wrap$1(ConfluenceExecutors.java:90)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$doInRequestContext$0(VCacheRequestContextOperations.java:50)
 at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:87)
 at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:71)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.doInRequestContext(VCacheRequestContextOperations.java:49)
 at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$withRequestContext$2(VCacheRequestContextOperations.java:66)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:748)
```


Answers:
author: Shannon S
body: Hello Luis,

Can you let me know what version of Confluence you're using? Do the spaces you're not able to delete share any properties, such as being personal spaces, or imported from somewhere?

If you create a test space are you able to delete that?

Regards,

Shannon

comments: author: Basilio
body: Hi Shannon,  

Yes, these spaces were imported from cloud and are team spaces. I had imported them on Confluence 6.4.0 where I'm facing the error.  

But it is important to know that I deleted all pages from these spaces, nevertheless I still cannot delete them.  

Regards


author: Shannon S
body: Thank you Luis!

Understood. Can you try the fix here and let me know if it works for you?

* [CONFSERVER-52755](https://jira.atlassian.com/browse/CONFSERVER-52755)

> ### Workaround {#toc-hId-1593069188}
>
> Some users have resolved this issue by running the command below to delete invalid notifications tied to deleted pages in the space (Similar to solution from [](https://jira.atlassian.com/browse/CONFSERVER-15964 "Unable to purge the trash if notification for old version of a page is present")~~[CONFSERVER-15964](https://jira.atlassian.com/browse/CONFSERVER-15964 "Unable to purge the trash if notification for old version of a page is present")~~):  
>
> ```
> DELETE FROM NOTIFICATIONSWHERE CONTENTID IN (  SELECT CONTENTID FROM CONTENT  WHERE (CONTENT_STATUS = 'deleted' AND SPACEID = <spaceid-here>)     OR PREVVER IN (       SELECT CONTENTID FROM CONTENT       WHERE CONTENT_STATUS = 'deleted' AND SPACEID = <spaceid-here>));
> ```

> :warning: With direct database manipulation, be sure to **test and validate** these changes in a test environment and create all necessary backups **prior to** rolling any changes into a Production environment.

If so, I can update the bug ticket with your Confluence version.

Regards,

Shannon


author: Basilio
body: Hi Shannon,

Unfortunately this script didn't solve the problem. I tried on my local environment. I'll try to reproduce in another instance before apply in production.

Regards


author: Shannon S
body: Luis,

Thank you for confirming.

There's a similar workaround here but you would need to search your logs to see if there's a problem with a particular page. If you deleted all the pages AND purged the trash entirely, then this shouldn't affect you, so please make sure the trash is indeed purged.

* [Deleting a space is not working](https://confluence.atlassian.com/confkb/deleting-a-space-is-not-working-due-to-foreign-key-constraint-394465190.html)

In addition this sounds similar since they were imported from Cloud, but according to this it was fixed in 6.0.2. You may want to check, regardless:

* [CONFSERVER-44257](https://jira.atlassian.com/browse/CONFSERVER-44257)

Regards,

Shannon


Tags: delete

space