gpt4 book ai didi

java - 尝试加载 CLOB 字段时,DBunit 生成 java.lang.ClassCastException : java. lang.String 无法转换为 oracle.sql.CLOB

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:24:14 29 4
gpt4 key购买 nike

我在 Oracle 11GR2 上使用最新版本的 DBUnit (2.4.7)。我正在使用 Java 6 (1.6.0_15) 和最新版本的 Oracle 客户端 jar (jdbc6.jar)

我一直无法将 CLOB Oracle 字段引用的任何数据从 XML 文件成功加载到数据库中。

我使用了各种版本的组合:

  • Oracle JDBC 库 ojdbc5.jar、ojdbc6.jar、oracle 10 jar
  • Hibernate 库等...我认为问题出在 DBUnit 上。请参阅下面的堆栈跟踪。

    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.5.0-CR-2</version>

    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.4.0.GA</version>

我正在运行 Java 6, 1.6.0_15。

我试过:

1) FlatXmlDataSet 使用这个定义

<MESSAGE msg_id="1" mtp_id="1" msg_detail="asadds" />

2) 使用这个定义的XmlDataSet

<table name="MESSAGE">
<column>MSG_ID</column>
<column>MTP_ID</column>
<column>MSG_DETAIL</column>
<row>
<value>1</value>
<value>1</value>
<value>dsad</value>
</row>
</table>

如有任何帮助,我们将不胜感激!

堆栈跟踪如下:

        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)ERROR [10032010 14:15:13,031] - exception creating EntityManager:  [] (MessageDAOTest.java:97)java.lang.RuntimeException: Exception in JpaDBTestCase        at com.ert.commons.junit4.hibernate.JpaDBTestCase.loadDbunitFiles(JpaDBTestCase.java:97)        at com.ert.ertmon.dao.ejb.impl.MessageDAOTest.setUpBeforeClass(MessageDAOTest.java:94)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)        at java.lang.reflect.Method.invoke(Method.java:597)        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)        at java.lang.reflect.Method.invoke(Method.java:597)        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to oracle.sql.CLOB        at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7898)        at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7511)        at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:7984)        at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:237)        at org.dbunit.dataset.datatype.ClobDataType.setSqlValue(ClobDataType.java:71)        at org.dbunit.database.statement.SimplePreparedStatement.addValue(SimplePreparedStatement.java:73)        at org.dbunit.database.statement.AutomaticPreparedBatchStatement.addValue(AutomaticPreparedBatchStatement.java:63)        at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:186)        at org.dbunit.AbstractDatabaseTester.executeOperation(AbstractDatabaseTester.java:190)        at org.dbunit.AbstractDatabaseTester.onSetup(AbstractDatabaseTester.java:103)        at com.ert.commons.junit4.hibernate.JpaDBTestCase.loadDbunitFile(JpaDBTestCase.java:136)        at com.ert.commons.junit4.hibernate.JpaDBTestCase.loadDbunitFiles(JpaDBTestCase.java:92)        ... 21 more

最佳答案

使用org.dbunit.ext.oracle.Oracle10DataTypeFactory

在数据工厂配置中。

关于java - 尝试加载 CLOB 字段时,DBunit 生成 java.lang.ClassCastException : java. lang.String 无法转换为 oracle.sql.CLOB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2419876/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com