java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 不能被转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10247702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:12:57  来源:igfitidea点击:

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

javajbossoracle11gspatialjdk1.6

提问by Rajkumar

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

应用版本:JBoss 7.0.0、Oracle 11g (ojdbc6.jar) 和 JDK 6 版本

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

当我尝试使用CLOB.createTemporary函数插入 CLOB 数据类型的值时遇到问题,得到以下异常。

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

在多个论坛中搜索后,没有找到任何解决方案。 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.

部署 WAR 文件和配置 JBoss oracle 驱动程序池配置所需的基本步骤已完成。但是,仍然无法解决这个问题。

Please provide solution to fix this problem.

请提供解决此问题的解决方案。

回答by Rajkumar

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).

总结:类加载器不应从服务器库/模块和 Web 存档(WAR 文件)中加载 Oracle 驱动程序。仅将 oracle 驱动程序保留在服务器库(JBoss 7 版本)中。

JBoss 7:

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>
      
  • 创建了一个新的 JBoss 部署描述符文件(jboss-deployment-structure.xml)

    1. 更新了jboss部署结构文件中的(ironjacamar-jdbc-1.0.3.Final.jar)iron模块
    2. 在 JBoss 7 结构中创建了 ojdbc6.jar 作为模块 更新了 jboss 部署结构文件中的 objbc 模块
    3. 例子:

      <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)

Web 模块:- 从 Web 存档(WAR 文件)中删除了 ojdbc6.jar 文件

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

如果您在解决过程中发现任何问题,请告诉我。

回答by Philippe Marschall

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.

这里发生的事情是 JBoss 用它自己的连接(oracle.jdbc.OracleConnection)包装了它自己的连接(org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6)。您必须调用 #getUnderlyingConnection() 来获取底层连接。

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));

回答by joe81

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

在使用 Jruby 1.7.2、JBoss 7.1 和 Oracle(oracle_enhanced 适配器)的 Rails 应用程序中遇到类似问题

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:

我将 jboss-deployment-structure.xml 放在 rails 应用程序的 config/ 目录中,并更新了 warbler 配置以将该文件包含在 war 文件中:

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

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

部署后一切正常......感谢很多。