java.lang.ClassCastException: oracle.sql.CLOB 不能转换为 oracle.sql.CLOB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17200815/
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
java.lang.ClassCastException: oracle.sql.CLOB cannot be cast to oracle.sql.CLOB
提问by user1807337
I recently upgraded an application to run using JAVA 7 and JBoss 7.1.1 This application was originally developed on JAVA 5 and Jboss 4.2.2. This application uses hibernate 3 for persistence.
我最近升级了一个应用程序以使用 JAVA 7 和 JBoss 7.1.1 运行这个应用程序最初是在 JAVA 5 和 Jboss 4.2.2 上开发的。此应用程序使用休眠 3 进行持久化。
On the new platform, the application is failing when there is an attempt to INSERT into a table with CLOB fields with the above error. I am using ojdbc14.jar (backend database Oracle 10.2.0.3)
在新平台上,当尝试 INSERT 到具有 CLOB 字段的表时,应用程序失败并出现上述错误。我正在使用 ojdbc14.jar(后端数据库 Oracle 10.2.0.3)
These are things that I have verified in jboss 7.1.1 configuration:
这些是我在 jboss 7.1.1 配置中验证过的:
- Creation of the correct module for Oracle. Ensured that ojdbc14.jar exists in the correct modules directory
- Ensured that there are no other conflicting ojdbc.jar existing anywhere else in the jboss directory
- Ensured that the application is not referring to a different ojdbc.jar.
- 为 Oracle 创建正确的模块。确保 ojdbc14.jar 存在于正确的模块目录中
- 确保 jboss 目录中的其他任何位置都没有其他冲突的 ojdbc.jar
- 确保应用程序没有引用不同的 ojdbc.jar。
Any insight would be helpful. I am pulling my hair trying to resolve this issue for almost a week now.
任何见解都会有所帮助。近一个星期以来,我一直在努力解决这个问题。
Thanks much
非常感谢
回答by user1807337
I fixed the problem. Posting this answer, hoping it might be useful to someone.
我解决了这个问题。发布此答案,希望它对某人有用。
When I was checking the instance type of the CLOB retrieved by the query, it came up as oracle.sql.CLOB. So I assumed it must have been a version mismatch of ojdbc.jar. I checked my project a gazillion times for multiple copies of the ojdb.jar. There were none.
当我检查查询检索到的 CLOB 的实例类型时,它出现为 oracle.sql.CLOB。所以我认为它一定是 ojdbc.jar 的版本不匹配。我为 ojdb.jar 的多个副本检查了我的项目无数次。没有。
Finally it turned out to be a clash between hibernate and ojdbc. I changed the reference to java.sql.Clob. Hibernate uses java.sql.Clob. This resolved the problem.
最后证明是hibernate和ojdbc之间的冲突。我更改了对 java.sql.Clob 的引用。Hibernate 使用 java.sql.Clob。这解决了问题。
回答by T-student
In my situation i m not using Hibernate but i use Jboss like container and i had to remove the module of oracle from the jboss-deployment-structure.xml so i could not use anymore the oracle.sql.CLOB and i had the same probelm
在我的情况下,我不使用 Hibernate,但我使用 Jboss 之类的容器,我不得不从 jboss-deployment-structure.xml 中删除 oracle 模块,所以我不能再使用 oracle.sql.CLOB 并且我有相同的问题
java.lang.ClassCastException: oracle.sql.CLOB cannot be cast to oracle.sql.CLOB
in the end i used
最后我用了
java.sql.Clob clobValue = (java.sql.Clob)result.getClob("EMIRFILE");
and works correctly. I hope this help someone.
并正常工作。我希望这对某人有帮助。