Unable to unwrap vendor specific JDBC types in JBoss EAP

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6
    • 7
  • JDBC / All Databases

Issue

  • java.sql.SQLException on statement.unwrap(oracle.jdbc.OracleCallableStatement.class)
  • java.lang.ClassCastException: oracle.jdbc.driver.OracleCallableStatementWrapper cannot be cast to oracle.jdbc.OracleCallableStatement

Resolution

Ensure that only one copy of the vendor specific driver exists in the system

Root Cause

Multiple copies of the 3rd party libraries (e.g. vendor specific JDBC driver) were present in the system

  • The datasource pool referenced a driver JAR (in the deployments directory) or driver module containing the driver JAR
  • The application packaged or referenced another module also containing the driver JAR

Diagnostic Steps

Use code1 like the below to confirm whether there are multiple copies of the same classes (loaded by different class loaders)

        // Get the application layer visible class / class loader
        Class c = Class.forName("oracle.jdbc.driver.OracleCallableStatementWrapper");
        System.out.println("------> Oracle class in current class loader is " + c + "@" + c.hashCode()
                + " loaded by " + c.getClassLoader());

        WrappedCallableStatementJDK6 wocStmt = (WrappedCallableStatementJDK6) conn.prepareCall(
                "{? = call PACKAGE.MY_FUNCTION(?,?,?,?)}");

        java.sql.CallableStatement cs = wocStmt.getUnderlyingStatement();

        // Get the class and class loader accessible to the managed pool (which creates connections and statements)
        System.out.println("------> getUnderlyingStatement() returned " + cs.getClass() + "@" + cs.getClass().hashCode()
                + " loaded by " + cs.getClass().getClassLoader());

        // Compare the application layer and pool layer classes / class loaders
1

To access WrappedCallableStatementJDK6, application code will require a dependency specification for the JBoss adapter module

Components
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.