6 Replies Latest reply on May 29, 2007 11:25 PM by Gil Sabado

    Reading of Oracle BLOB works with JBoss 3.2.3 but fails with

    Volker Sommerfeld Newbie

      With JBoss 3.2.3 the following works without any problems. Yet, with JBoss 3.2.5 there is a ClassCastException:

      I read a BLOB from an Oracle database:

      //rset comes from a statement such as SELECT blob_data from test_table;
      if (logger.isInfoEnabled())
       logger.info("Class of the resultSet: " + rset.getClass().getName());
      InputStrean inStream = ((OracleResultSet)rset).getBLOB(1).getBinaryStream();
      


      With JBoss 3.2.3, the class of the result set is an Oracle result set:
      INFO (OracleAuthenticationServer.java : 694) - Class of the resultSet: oracle.
      jdbc.driver.OracleResultSetImpl
      


      Yet, with JBoss 3.2.5 it is a wrapper class. Therefore I get a ClassCastException:
      11:09:59,804 INFO [OracleAuthenticationServer] Class of the resultSet: org.jbos
      s.resource.adapter.jdbc.WrappedResultSet
      11:09:59,804 ERROR [LogInterceptor] RuntimeException:
      java.lang.ClassCastException
       at de.srp_gmbh.db.OracleDatabaseAdapter.getOracleResultSet(OracleDatabas
      eAdapter.java:251)
       at de.srp_gmbh.oma.server.authentication.OracleAuthenticationServer.chec
      kUser(OracleAuthenticationServer.java:695)
       at de.srp_gmbh.oma.server.authentication.AbstractSQLAuthenticationServer
      .validUser(AbstractSQLAuthenticationServer.java:574)
       at de.srp_gmbh.oma.server.authentication.AuthenticationServer.validUser(
      AuthenticationServer.java:387)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
      tatelessSessionContainer.java:683)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      ke(CachedConnectionInterceptor.java:185)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
      elessSessionInstanceInterceptor.java:72)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:84)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:282)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
      48)
       at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:120)
       at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
      ryFinderInterceptor.java:122)
       at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessi
      onContainer.java:331)
       at org.jboss.ejb.Container.invoke(Container.java:723)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.
      java:60)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.
      java:185)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
       at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
      360)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
       at sun.rmi.transport.Transport$1.run(Transport.java:148)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
       at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
      60)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:701)
       at java.lang.Thread.run(Thread.java:534)
      


      How can I extract the Oracle result set from the wrapper class?


        • 1. Re: Reading of Oracle BLOB works with JBoss 3.2.3 but fails
          Volker Sommerfeld Newbie

          In order to solve the problem, I found the JAR $JBOSS_3.2.5_HOME/server/default/lib/jboss-common-jdbc-wrapper.jar. The JAR with the Oracle driver is also in the directory $JBOSS_3.2.5_HOME/server/default/lib. Then, I succesfully invoked the method getUnderlyingResultSet() of the WrappedResultSet in order to get the underlying Oracle result set. Yet, when I try to cast the underlying result set to an Oracle result set, I get the ClassCastException.

          Because I get the ClassCastException when I try to cast an Oracle result set to an Oracle result set, I assume that there is a class loader problem (Has the class loading changed from JBoss 3.2.3 to JBoss 3.2.5?). Could somebody help me with this new information?

          Java-Code:

          if (logger.isInfoEnabled())
           logger.info("Class of the resultSet: " + rset.getClass().getName());
          ResultSet underlyingResultSet = ((org.jboss.resource.adapter.jdbc.WrappedResultSet)rset).getUnderlyingResultSet();
          if (logger.isInfoEnabled())
           logger.info("Class of the underlying resultSet: " + underlyingResultSet.getClass().getName());
          InputStrean inStream = ((OracleResultSet)underlyingResultSet).getBLOB(1).getBinaryStream();
          


          JBoss-Log:
          11:47:39,046 INFO [OracleAuthenticationServer] Class of the resultSet: org.jbos
          s.resource.adapter.jdbc.WrappedResultSet
          11:47:39,046 INFO [OracleAuthenticationServer] Class of the underlying resultSe
          t: oracle.jdbc.driver.OracleResultSetImpl
          11:47:39,140 ERROR [LogInterceptor] RuntimeException:
          java.lang.ClassCastException
           at de.srp_gmbh.db.OracleDatabaseAdapter.getOracleResultSet(OracleDatabas
          eAdapter.java:251)
           at de.srp_gmbh.oma.server.authentication.OracleAuthenticationServer.chec
          kAdminUser(OracleAuthenticationServer.java:548)
           at de.srp_gmbh.oma.server.authentication.AuthenticationServer.checkAdmin
          User(AuthenticationServer.java:151)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
          java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
          sorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:324)
           at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
          tatelessSessionContainer.java:683)
           at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
          ke(CachedConnectionInterceptor.java:185)
           at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
          elessSessionInstanceInterceptor.java:72)
           at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
          rceptor.java:84)
           at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
          torCMT.java:282)
           at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:1
          48)
           at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
          java:120)
           at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
           at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
          ryFinderInterceptor.java:122)
           at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessi
          onContainer.java:331)
           at org.jboss.ejb.Container.invoke(Container.java:723)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
          java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
          sorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:324)
           at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.
          java:60)
           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
           at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.
          java:185)
           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
           at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
          360)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
          java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
          sorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:324)
           at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
           at sun.rmi.transport.Transport$1.run(Transport.java:148)
           at java.security.AccessController.doPrivileged(Native Method)
           at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
           at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
          60)
           at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
          .java:701)
           at java.lang.Thread.run(Thread.java:534)
          


          I use oracle 9i and the Oracle thin driver.


          • 2. Re: Reading of Oracle BLOB works with JBoss 3.2.3 but fails
            Volker Sommerfeld Newbie

            P.S. You may wonder why it is important for me to get the underlying Oracle result set. The reason is that for writing a BLOB into an Oracle database I need the Oracle BLOB (OracleResultSet.getBLOB(i)). Only with this Oracle-specific BLOB I can write my BLOB data into an Oracle database (this is specific for Oracle, see for instance http://forum.java.sun.com/thread.jsp?thread=325315&forum=48&message=1319379).

            • 3. Re: Reading of Oracle BLOB works with JBoss 3.2.3 but fails
              Adrian Brock Master

              underlyingResultSet.getClass().getInterfaces();

              check the classloaders of the classes as well.

              • 4. Re: Reading of Oracle BLOB works with JBoss 3.2.3 but fails
                Bhaumik Parekh Newbie

                Hi.. I am getting the same problem using Oracle 9i with JBoss AS 4.0.3.

                Can someone help me out...

                • 5. Re: Reading of Oracle BLOB works with JBoss 3.2.3 but fails
                  Sidney Zurch Novice

                  This works with Oracle ARRAYs, so it should work with BLOBs.

                  Cast the underlying ResultSet:


                  ResultSet wrs = s.executeQuery(statementText);

                  Log("Wrapped ResultSet class:" + wrs.getClass().getName());

                  ResultSet urs =
                  ((org.jboss.resource.adapter.jdbc.WrappedResultSet) wrs)
                  .getUnderlyingResultSet();

                  Log("Underlying ResultSet class:" + urs.getClass().getName());

                  OracleResultSet rs = (OracleResultSet) urs;

                  Log("Oracle ResultSet class:" + rs.getClass().getName());



                  • 6. Re: Reading of Oracle BLOB works with JBoss 3.2.3 but fails
                    Gil Sabado Newbie

                    On my case, this code snippets runs on Oracle 9i, but when I deploy the WAR using Oracle 10g as the backend, exception occured on casting

                    here is the code:

                    if (id!= null) {
                    stmt2=conn.prepareStatement("SELECT content from pps_designdocument_revs where id = "+id);
                    rs=stmt2.executeQuery();
                    if (rs!=null && rs.next()){
                    oracle.sql.BLOB objectBlob = (oracle.sql.BLOB)rs.getObject("CONTENT");
                    byte[] buffer = new byte[objectBlob.getBufferSize()];
                    int bytesRead = 0;
                    inputStream = desDocRev.getContents();
                    outputStream = objectBlob.getBinaryOutputStream();
                    while ((bytesRead = inputStream.read(buffer)) != -1){
                    outputStream.write(buffer, 0, bytesRead);
                    }
                    outputStream.flush();
                    outputStream.close();
                    inputStream.close();
                    conn.commit();
                    }
                    DataSourceBroker.close(rs);
                    DataSourceBroker.close(stmt2);
                    }else{
                    conn.rollback();
                    }

                    Here is the error:

                    javax.servlet.ServletException: oracle.sql.BLOB cannot be cast to oracle.sql.BLOB