I am getting "ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection" when using Springframework on JBoss EAP6.
Environment
-Red Hat JBoss Enterprise Application Platform (EAP)
-6.x
Issue
After i add oracle dependency on org.jboss.ironjacamar.jdbcadapters module's module.xml like below:
<module xmlns="urn:jboss:module:1.1" name="org.jboss.ironjacamar.jdbcadapters">
...
<dependencies>
<module name="oracle module"/>
</dependencies>
</module>
I got error Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection
org.springframework.dao.InvalidDataAccessApiUsageException: OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection
Resolution
The issue is that the OracleLobHandler needs an Oracle Connection, and not a wrapped connection that is supplied by a Datasource pool.
Looking at the Spring source code for the OracleLobHandler[1], you need to set a NativeJdbcExtractor that will extract the underlying connection from the wrapped connection supplied from the JBoss Datasource Pool.
Configuring this Lob handler in your application is where you would need to set the appropriate Spring class that extracts a connection for a JBoss supplied wrapped connection. The class to set for the NativeJdbcExtractor will be something like:
org.springframework.jdbc.support.nativejdbc.JBossNativeJdbcExtractor
I see in your ApplicationContext.xml you are defining a lobHandler.
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
</bean>
Can you try changing this to:
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.JBossNativeJdbcExtractor" lazy-init="true"/>
The only other thing is whether the version of Spring you are using included integration with Jboss EAP6.
The older versions of Spring used these constants in the JBossNativeJdbcExtractor class:
private static final String WRAPPED_CONNECTION_NAME = "org.jboss.resource.adapter.jdbc.WrappedConnection";
private static final String WRAPPED_STATEMENT_NAME = "org.jboss.resource.adapter.jdbc.WrappedStatement";
private static final String WRAPPED_RESULT_SET_NAME = "org.jboss.resource.adapter.jdbc.WrappedResultSet";
these need to be updated to:
private static final String WRAPPED_CONNECTION_NAME = "org.jboss.jca.adapters.jdbc.WrappedConnection";
private static final String WRAPPED_STATEMENT_NAME = "org.jboss.jca.adapters.jdbc.WrappedStatement";
private static final String WRAPPED_RESULT_SET_NAME = "org.jboss.jca.adapters.jdbc.WrappedResultSet";
It looks like version 3.2.4 of SpringFramework integrates with EAP6.
Another option, depending on the jdbc driver used, is to use the DefaultLobHandler. [2]
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.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
