11 Replies Latest reply on Jan 28, 2014 11:39 AM by Philippe Marschall

    ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet

    Ravi Patil Newbie

      Hi All,

       

      My environment details are :

       

      JBOSS EAP 6.1.0

      oracle 11g

      ojdbc6.jar

       

      I am trying to :

       

      String sql = "SELECT query ...";
      Statement stmt = ConnMan.getConnection("MyDS1").prepareStatement(sql);
      ResultSet rs = stmt.executeQuery();
      NativeJdbcExtractor njdbcExtractor = new NativeJdbcExtractor();
      OracleResultSet ors = (OracleResultSet) njdbcExtractor.getNativeResultSet(rs);                  
      XMLType xml = null;
      try {
          Integer type = rs.getInt(1);
          OPAQUE opaque = ors.getOPAQUE(2);
          xml = XMLType.createXML(opaque);
      
      
      

       

      OracleResultSet ors = (OracleResultSet) njdbcExtractor.getNativeResultSet(rs); 

      Highlighted line is throwing this exception. whereas the exact code works fine in weblogic.

       

      Please help!

       

      Thanks,

      Ravi

        • 1. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
          jaikiran pai Master

          Post the entire exception stacktrace and the what does the implementation of njdbcExtractor.getNativeResultSet look like?

          • 2. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
            Jesper Pedersen Master

            WrappedResultSet wrs = (WrappedResultSet)rs;

            OracleResultSet ors = (OracleResultSet)wrs.getUnderlyingResultSet();

            • 3. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
              Ravi Patil Newbie

              Hi Jay,

              NativeJdbcExtractor comes from spring package :

              org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor

               

              The stacktrace is :

               

              Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedResultSetJDK6 cannot be cast to oracle.jdbc.OracleResultSet

                  at com.myorg.business.OrderBusiness.validateExtendable(OrderBusiness.java:962)

                  at com.myorg.business.OrderBusiness.orderCommit(OrderBusiness.java:742)

                  at com.myorg.business.OrderBusiness$$FastClassByCGLIB$$ad523028.invoke(<generated>)

                  at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

                  at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)

                  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.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)

                  at com.myorg.business.OrderBusiness$$EnhancerByCGLIB$$8614975f.orderCommit(<generated>)

                  at com.myorg.business.OrderBusiness$$FastClassByCGLIB$$ad523028.invoke(<generated>)

                  at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

                  at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)

                  at com.myorg.framework.aop.ChunkingInterceptor.invoke(ChunkingInterceptor.java:33)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at com.myorg.framework.aop.DatabaseContextInterceptor.invoke(DatabaseContextInterceptor.java:264)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)

                  at com.myorg.business.OrderBusiness$$EnhancerByCGLIB$$7db09169.orderCommit(<generated>)

                  at com.myorg.impl.OrderImpl.orderCommit(OrderImpl.java:224)

                  at com.myorg.impl.OrderImpl$$FastClassByCGLIB$$945214e8.invoke(<generated>)

                  at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

                  at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)

                  at com.myorg.framework.aop.DebugInterceptor.invoke(DebugInterceptor.java:204)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at com.myorg.framework.aop.SecurityInterceptor.invoke(SecurityInterceptor.java:491)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:126)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)

                  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

                  at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)

                  at com.myorg.impl.OrderImpl$$EnhancerByCGLIB$$2fa29894.orderCommit(<generated>)

                  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 sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)

                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                  at java.lang.reflect.Method.invoke(Method.java:597)

                  at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

                  at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

                  at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.tx.EjbBMTInterceptor.handleInvocation(EjbBMTInterceptor.java:104)

                  at org.jboss.as.ejb3.tx.BMTInterceptor.processInvocation(BMTInterceptor.java:56)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

                  at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:79)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

                  at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

                  at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

                  at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:329)

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$100(MethodInvocationMessageHandler.java:70)

                  at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:203)

                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)

                  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

                  at java.util.concurrent.FutureTask.run(FutureTask.java:138)

                  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                  at java.lang.Thread.run(Thread.java:662)

                  at org.jboss.threads.JBossThread.run(JBossThread.java:122)

               

              Thanks,

              Ravi

              • 4. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                Philippe Marschall Expert

                This should do the trick:

                 

                OracleResultSet ors = rs.unwrap(OracleResultSet.class);

                • 5. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                  Ravi Patil Newbie

                  Phillippe, It does work! Thanks. But I want to use the Spring based Native Jdbc Extractor.

                   

                  I want to know why it doesn't work in JBoss when the same lines of code works fine in weblogic.?

                   

                  I agree that JBOSS has WrappedResultSetJDK6 which the other way implements java.sql.ResultSet. But still there should not be code inconsistency I believe.

                  • 6. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                    jaikiran pai Master

                    Ravi Patil wrote:

                     

                     

                    I agree that JBOSS has WrappedResultSetJDK6 which the other way implements java.sql.ResultSet. But still there should not be code inconsistency I believe.

                    Typically you wouldn't need to get the underlying ResultSet and you would just work with the standard Java API and that's where the code would be portable and consistent. However, since the application you are using appears to be require the underlying OracleResultSet, you have to resort to vendor specific APIs. Apparently WebLogic doesn't require any special handling to get to the underlying ResultSet but it's not mandated that, that be the case.

                    • 7. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                      Ravi Patil Newbie

                      Thanks Jai,

                       

                      Then with JBoss to get the underlying ResultSet, we must unwrap. Isn't it you mean?

                      • 8. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                        Philippe Marschall Expert

                        Ravi Patil wrote:

                         

                        Phillippe, It does work! Thanks. But I want to use the Spring based Native Jdbc Extractor.

                        You could use JBossNativeJdbcExtractor but if you can do it with standard JDBC API in a way that's portable across application servers and doesn't even require Spring then I have to ask why.

                        • 9. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                          Ravi Patil Newbie

                          Hi Phileppe,

                           

                          Keeping Weblogic App Server in mind for a while, I have not checked your suggested fix. But the ResultSet that we get while using weblogic will be "ResultSet" Unlike Jboss's WrappedResultSetJDK6. Will the unwrap work over there?

                          • 10. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                            Ravi Patil Newbie

                            Will it be the same case for WrappedConnectionJDK6, I think we get "no wrapper available for OracleConnection"

                            • 11. Re: ClassCastException: WrappedResultSetJDK6 cannot be cast to OracleResultSet
                              Philippe Marschall Expert

                              Ravi Patil wrote:

                               

                              Hi Phileppe,

                               

                              Keeping Weblogic App Server in mind for a while, I have not checked your suggested fix. But the ResultSet that we get while using weblogic will be "ResultSet" Unlike Jboss's WrappedResultSetJDK6. Will the unwrap work over there?

                              It should because the JDBC specification requires it.