java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast
Asked Answered
P

3

6

Application Version: JBoss 7.0.0, Oracle 11g (ojdbc6.jar) and JDK 6 version

I have a problem when I am trying to insert the value for CLOB Data type using CLOB.createTemporary function, getting the below exception.

java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection

After searching in multiple forums, did not find any solution. https://forums.oracle.com/forums/thread.jspa?threadID=279238

Basic steps required to deploy a WAR file and configuring the JBoss oracle driver pool configuration is done. But, still not able to get through this issue.

Please provide solution to fix this problem.

Pearsall answered 20/4, 2012 at 13:55 Comment(3)
This might help you.Chantellechanter
Could you replace ojdbc6.jar with ojdbc14.jar and check the driver class name oracle.jdbc.OracleDriverInterdigitate
Phani, I'm using Java 6 version and the corresponding driver for connecting to oracle should be ojdbc6.jar. May know how are you relating this with ojdbc14.jar file?Pearsall
P
9

I have solved my problem with the below approach.

Summary: Class loader should not load the Oracle driver from server lib/modules and in web archive (WAR file). Keep the oracle driver only in server lib (JBoss 7 ver).

JBoss 7:

  • Created a new JBoss deployment descriptor file(jboss-deployment-structure.xml)

    1. Updated the (ironjacamar-jdbc-1.0.3.Final.jar) iron module in the jboss deployment structure file
    2. Created the ojdbc6.jar as module in the JBoss 7 structure Updated the objbc module in the jboss deployment structure file
    3. Example:

      <jboss-deployment-structure> 
          <deployment>
              <dependencies>
                  <module name="org.jboss.ironjacamar.jdbcadapters" slot="main"/>
                  <module name="com.oracle.ojdbc6" slot="main"/>
              </dependencies>
          </deployment> 
      </jboss-deployment-structure>
      

Web module: - Removed the ojdbc6.jar file from the web archive(WAR file)

If you find any issue in solving, please let me know.

Pearsall answered 23/4, 2012 at 9:50 Comment(2)
Solution is great but take attention, the module names are configured in JBoss self. I had to change com.oracle.ojdbc6 to com.oracle.Panties
Hi @Rajkumar, I'm facing the issue and situation seems similar. can you please assist? https://mcmap.net/q/1773288/-i-39-m-getting-classcastexception-wrappedpreparedstatementjdk8-cannot-be-cast-to-sqlserverpreparedstatement/2174455Lanham
P
1

What's happening here is that JBoss wraps the oracle connection (oracle.jdbc.OracleConnection) with it's own one (org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6). You have to call #getUnderlyingConnection() to get the underlying connection.

WrappedConnection wrapped = (WrappedConnection) conn;
CLOB clob = CLOB.createTemporary(wrapped.getUnderlyingConnection(), true, CLOB.DURATION_SESSION);

However I ask myself whether the following wouldn't work as well in your case.

ps.setClob(4, new StringReader(data));
Psychometrics answered 23/4, 2012 at 5:8 Comment(2)
Hi Philippe, I can understand your answer. The problem now I'm facing is, I'm not able to type cast the "conn" object to WrappedConnection object. While I try to typecast, I'm get this exception "java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection"Pearsall
So WrappedConnection#getUnderlyingConnection() again returns a WrappedConnectionJDK6? Have you tried to delete the whole CLOB.createTemporary code (and the cast to WrappedConnection) and just go with ps.setClob(4, new StringReader(data));Psychometrics
S
0

Got a similar problem in a Rails App with Jruby 1.7.2, JBoss 7.1 and Oracle (oracle_enhanced adapter)

Java::JavaLang::ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection

This solution worked for me.

I put the jboss-deployment-structure.xml in the config/ directory of the rails app and updated the warbler config to include the file in the war file:

config.webinf_files += FileList["config/jboss-deployment-structure.xml"]

After deploy all worked fine ... Thx a lot.

Sulphonate answered 21/1, 2013 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.