Uploaded image for project: 'Confluence Server and Data Center'
  1. Confluence Server and Data Center
  2. CONFSERVER-20793

Confluence logs a ClassCastException Tomcat 6.0.27 or later when accessing Oracle.

    XMLWordPrintable

    Details

      Description

      Relates to CSP-49854, and in this specific case the issue occurs with Oracle. This problem can affect other databases as well if there is an internal requirement in spring or hibernate to access the native Connection. The main reason this is required for Oracle is for hibernate to access to proprietary Oracle lob api's.

      From tomcat 6.0.27 the dbcp libraries have been upgraded from 1.2 to 1.3. Some of the internals of this library changed so that there's an additional layer of proxies on the Connection.

      In Tomcat the dbcp library is repackaged by tomcat into it's own package (org.apache.tomcat.dbcp.dbcp), this appears to have occurred since Tomcat 5.5. This means the CommonsDbcpNativeJdbcExtractor in the automaticJdbcExtractor bean defined in productionDatabaseContext.xml is not applied.

      By luck (presumably), the default NativeJdbcExtractor provided (org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor) is able to extract the Native connection from dbcp 1.2.x since. However, this no longer work when dbcp was upgraded to 1.3, hence exceptions similar to those shown below.

      The resolution is quite simple - add an additional dbcp mapping for the org.apache.tomcat.dbcp.dbcp package.


      Example stacktrace.

      java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolableConnection cannot be cast to oracle.jdbc.OracleConnection
              at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.createLob(OracleLobHandler.java:357)
              at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.setClobAsCharacterStream(OracleLobHandler.java:311)
              at com.atlassian.hibernate.BucketClobStringType.nullSafeSet(BucketClobStringType.java:155)
              at net.sf.hibernate.type.CustomType.nullSafeSet(CustomType.java:118)
              at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:387)
              at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:460)
              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 net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
              at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:510)
              at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
              at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
              at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:139)
              at com.atlassian.sal.spring.component.SpringHostContextAccessor.doInTransaction(SpringHostContextAccessor.java:82)
              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 com.atlassian.plugin.osgi.hostcomponents.impl.DefaultComponentRegistrar$ContextClassLoaderSettingInvocationHandler.invoke(DefaultComponentRegistrar.java:129)
              at $Proxy183.doInTransaction(Unknown Source)
              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 com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(HostComponentFactoryBean.java:147)
              at $Proxy183.doInTransaction(Unknown Source)
              at com.atlassian.sal.core.transaction.HostContextTransactionTemplate.execute(HostContextTransactionTemplate.java:21)
              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:307)
              at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
              at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
              at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
              at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
              at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
              at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
              at $Proxy286.execute(Unknown Source)
              at com.atlassian.gadgets.renderer.internal.BlobCrypterImpl.getKey(BlobCrypterImpl.java:38)
              at com.atlassian.gadgets.renderer.internal.BlobCrypterImpl.<init>(BlobCrypterImpl.java:32)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
              at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
              ... 54 more
      Caused by: java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolableConnection cannot be cast to oracle.jdbc.OracleConnection
              at oracle.sql.CLOB.createTemporary(CLOB.java:1093)
              at oracle.sql.CLOB.createTemporary(CLOB.java:1037)
              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.jdbc.support.lob.OracleLobHandler$OracleLobCreator.prepareLob(OracleLobHandler.java:393)
              at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.createLob(OracleLobHandler.java:340)
              ... 112 more
      

        Attachments

          Activity

            People

            Assignee:
            cpetchell Petch
            Reporter:
            cpetchell Petch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: