1 Reply Latest reply on Nov 17, 2004 12:14 PM by nappinc

    ClassCastException using Oracle 9i DataSource

      Hi,

      I'm getting what appears to be a class loader problem when using an Oracle data source in JBoss 4.0.0. When using direct connections, I don't get any errors. On other app servers, I don't get any errors. I have copied the Oracle JDBC driver into the shared "lib" directory, excluded it from my .ear file, and I don't have any other applications deployed to the same server.

      The error only happens when saving some CLOB data (I can perform other queries or updates fine). It's deep within the Oracle driver code, but I assume it's trying to cast the connection to an "OracleConnection".

      The error is:

      2004-11-16 17:02:24,196 ERROR [org.jboss.web.localhost.Engine] StandardWrapperVa
      lve[saveXmlObject]: Servlet.service() for servlet saveXmlObject threw exception
      java.lang.ClassCastException
      at oracle.jdbc.driver.OracleConnection.physicalConnectionWithin(OracleConnection.java:5174)
      at oracle.sql.CLOB.createTemporary(CLOB.java:1009)
      at oracle.sql.CLOB.createTemporary(CLOB.java:956)
      at com.abmuk.oms.core.common.database.DBUtils.getTemporaryClob(DBUtils.java:252)

      I'd expect to get this error if the Oracle classes were being loaded twice (once by the JNDI code, once in my application), but I can't see how that would be happening.

      My datasources seem to be fine (I can do other read and writes) but for completeness it's here:

      <?xml version="1.0" encoding="UTF-8"?>

      <local-tx-datasource>
      <jndi-name>readonly</jndi-name>
      <connection-url>
      jdbc:oracle:thin:@abmlindev:1522:omsdev
      </connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      </local-tx-datasource>

      <local-tx-datasource>
      <jndi-name>writeable</jndi-name>
      <connection-url>
      jdbc:oracle:thin:@abmlindev:1522:omsdev
      </connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      </local-tx-datasource>


      (The username and password is set inside the application).

      Any help or advice would be gratefully received.

      thanks,

      Chris Nappin.

        • 1. Re: ClassCastException using Oracle 9i DataSource

          I've since resolved the issue. At the risk of answering my own question, I'll post my solution here to help anyone else who gets the same issue.

          It was actually a genuine ClassCastException, and nothing to do with multiple classloaders (I overlooked the simple issue!). We are calling the following Oracle-specific API:

          CLOB.createTemporary(connection, cacheFlag, duration);

          Although this takes a plain old JDBC "Connection" as a parameter, the Oracle code within this method then tries to cast it to an "OracleConnection" - to get access to the Oracle-specific functionality. This implementation is vulnerable to any connection pooling mechanism that uses a wrapper class (such as JBoss's).

          The solution is to check if the Connection is actually a "org.jboss.resource.adapter.jdbc.WrappedConnection" and if so call "getUnderlyingConnection()" (which if you're using the Oracle driver will then return the underlying OracleConnection instance), then pass that to the Oracle API.

          I can see I'm going to need similar code for any other pooling mechanisms on other app servers that use wrapper classes. Ho hum!