Steps to reproduce:

      1. Create a template in a space.
      2. Edit the template
      3. Try deleting the template

      You get the following error:

      Cause:
      org.springframework.jdbc.UncategorizedSQLException: (HibernateTemplate): encountered SQLException [failed batch]; nested exception is java.sql.BatchUpdateException: failed batch
      at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:99)
      caused by: java.sql.BatchUpdateException: failed batch
      at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)

      Stack Trace:

      org.springframework.jdbc.UncategorizedSQLException: (HibernateTemplate): encountered SQLException [failed batch]; nested exception is java.sql.BatchUpdateException: failed batch
      java.sql.BatchUpdateException: failed batch
      at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
      at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
      at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
      at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
      at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
      at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
      at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2397)
      at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
      at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
      at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:472)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:397)
      at com.atlassian.xwork.interceptors.XWorkTransactionInterceptor$1.beforeResult(XWorkTransactionInterceptor.java:89)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:181)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor.intercept(DefaultWorkflowInterceptor.java:55)
      at com.atlassian.confluence.core.ConfluenceWorkflowInterceptor.intercept(ConfluenceWorkflowInterceptor.java:39)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.atlassian.confluence.core.ConfluenceValidationInterceptor.intercept(ConfluenceValidationInterceptor.java:16)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.atlassian.confluence.security.actions.PermissionCheckInterceptor.intercept(PermissionCheckInterceptor.java:47)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.atlassian.confluence.pages.actions.PageAwareInterceptor.intercept(PageAwareInterceptor.java:114)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.atlassian.confluence.spaces.actions.SpaceAwareInterceptor.intercept(SpaceAwareInterceptor.java:67)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.atlassian.confluence.core.actions.LastModifiedInterceptor.intercept(LastModifiedInterceptor.java:39)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.atlassian.confluence.core.ConfluenceAutowireInterceptor.intercept(ConfluenceAutowireInterceptor.java:25)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.atlassian.xwork.interceptors.XWorkTransactionInterceptor.intercept(XWorkTransactionInterceptor.java:98)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
      at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
      at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:115)
      at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:229)
      at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:199)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:117)
      at com.atlassian.confluence.util.profiling.ProfilingPageFilter.parsePage(ProfilingPageFilter.java:137)
      at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:51)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.core.filters.ServletContextThreadLocalFilter.doFilter(ServletContextThreadLocalFilter.java:21)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.confluence.util.UserThreadLocalFilter.doFilter(UserThreadLocalFilter.java:44)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.seraph.filter.SecurityFilter.doFilter(SecurityFilter.java:182)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.seraph.filter.LoginFilter.doFilter(LoginFilter.java:159)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.confluence.util.ClusterHeaderFilter.doFilter(ClusterHeaderFilter.java:35)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.johnson.filters.JohnsonFilter.doFilter(JohnsonFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
      at com.atlassian.spring.filter.FlushingSpringSessionInViewFilter.doFilterInternal(FlushingSpringSessionInViewFilter.java:29)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.util.profiling.filters.ProfilingFilter.doFilter(ProfilingFilter.java:122)
      at com.atlassian.core.filters.ProfilingAndErrorFilter.doFilter(ProfilingAndErrorFilter.java:27)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.confluence.util.RequestCacheThreadLocalFilter.doFilter(RequestCacheThreadLocalFilter.java:31)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.core.filters.gzip.GzipFilter.doFilter(GzipFilter.java:61)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.atlassian.core.filters.AbstractEncodingFilter.doFilter(AbstractEncodingFilter.java:37)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)

            [CONFSERVER-7854] Error deleting template that has been edited

            Linh Pham added a comment -

            Matthew,
            Your workaround leaves orphaned records in the table.
            I prefer to manually remove the child records for the main template (on request), and then delete the main template via the UI.

            Otherwise, you could disable the foreign key constraint FKBC7CE96A17D4A070 directly.

            Linh Pham added a comment - Matthew, Your workaround leaves orphaned records in the table. I prefer to manually remove the child records for the main template (on request), and then delete the main template via the UI. Otherwise, you could disable the foreign key constraint FKBC7CE96A17D4A070 directly.

            This issue can also manifest as a LazyInitializationException when the missing page template reference is used.

            m@ (Inactive) added a comment - This issue can also manifest as a LazyInitializationException when the missing page template reference is used.

            This exception is caused because the prever foreign key constraint is throwing an error back to Hibernate.
            Hibernate is bundling all the exceptions from the batch and reporting the BatchUpdateException.
            The fix was implemented to delete the previous versions of the templates to make sure this foreign key was never broken.
            This issue also manifests itself as an ObjectNotFoundException when using MySQL with MyISAM storage engine (which is the default and doesn't support foreign key constraints).

            You can use this SQL work around to clean up previous versions of templates to work around this issue. You may need to do this even if you have upgraded to a "fixed" version as the data may be corrupted by this issue before you upgraded.

            Please back up your database before attempting to run any of these scripts.

            Run the following database query to confirm the problem.

            SELECT count(a.templateid)
            FROM PAGETEMPLATES a
            WHERE a.prevver is not null
            AND a.prevver not in (SELECT b.templateid FROM PAGETEMPLATES b)

            If you are affected by this issue, this query will return more than zero results.

            To remove these broken page templates, you can update the PAGETEMPLATES table.

            UPDATE PAGETEMPLATES a
            LEFT JOIN PAGETEMPLATES b ON a.prevver=b.templateid
            SET a.prevver=null WHERE b.templateid IS NULL

            This will update all the PAGETEMPLATES that have a prever reference to an unknown templateid to null. This affectively breaks the edit history of the page templates but will work around this issue.

            NOTE: These scripts where tested on MySQL and may need minor modifications to run in other database servers.

            m@ (Inactive) added a comment - This exception is caused because the prever foreign key constraint is throwing an error back to Hibernate. Hibernate is bundling all the exceptions from the batch and reporting the BatchUpdateException. The fix was implemented to delete the previous versions of the templates to make sure this foreign key was never broken. This issue also manifests itself as an ObjectNotFoundException when using MySQL with MyISAM storage engine (which is the default and doesn't support foreign key constraints). You can use this SQL work around to clean up previous versions of templates to work around this issue. You may need to do this even if you have upgraded to a "fixed" version as the data may be corrupted by this issue before you upgraded. Please back up your database before attempting to run any of these scripts. Run the following database query to confirm the problem. SELECT count(a.templateid) FROM PAGETEMPLATES a WHERE a.prevver is not null AND a.prevver not in (SELECT b.templateid FROM PAGETEMPLATES b) If you are affected by this issue, this query will return more than zero results. To remove these broken page templates, you can update the PAGETEMPLATES table. UPDATE PAGETEMPLATES a LEFT JOIN PAGETEMPLATES b ON a.prevver=b.templateid SET a.prevver=null WHERE b.templateid IS NULL This will update all the PAGETEMPLATES that have a prever reference to an unknown templateid to null. This affectively breaks the edit history of the page templates but will work around this issue. NOTE: These scripts where tested on MySQL and may need minor modifications to run in other database servers.

              Unassigned Unassigned
              sleberrigaud Samuel Le Berrigaud
              Affected customers:
              0 This affects my team
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: